CSV_LookupV_&_LookupH  

  RSS

Arcadia35
(@arcadia35)
New Member
Registrado: hace 4 meses
Respuestas: 2
30/03/2020 3:00 pm  

Good afternoon all,

First of all I have to thank the developers of MyOpenLab to give us the oportunity to create and experience with their opensource software. I am really surprised with Myopenlab and I hope development continues.

Doing my first approaches to the program I was wondering if there was a way to look a known value on a CSV file, or at least its column and row. If you have a CSV file in which the value "X", column 1, has some values in columns 2 or 3 that you would like to know, is there any element in Myopenlab capable of that?

 

Greetings and thanks


Citar
Arcadia35
(@arcadia35)
New Member
Registrado: hace 4 meses
Respuestas: 2
02/04/2020 7:10 am  

I messed up alittle with java code using the 2D-Getter element base. I think I am close to what I wanted but still does not work, any idea? (I commented the last part)

//********************************
//* Autor :
//* Date :
//* Email :
//* licence :
//********************************

import VisualLogic.*;
import java.awt.*;
import java.awt.event.*;
import tools.*;
import VisualLogic.variables.*;
import java.util.*;
import javax.swing.*;

public class CircuitElement extends JVSMain
{
private Image image;
private VSObject in;
private VSInteger col;
private VSInteger row;
private VSBoolean read;
private VSObject value;
private VSObject out;
private VSString look;
// Properties
// Inputs

public void onDispose()
{
if (image!=null) image.flush();
image=null;
}

public void paint(java.awt.Graphics g)
{
if (image!=null) drawImageCentred(g,image);
}

public void setPropertyEditor()
{
localize();
}

private void localize()
{
String language;
int d=6;
language="en_US";
language="es_ES";
}
public void init()
{
initPins(0,2,0,5);
initPinVisibility(false,true,false,true);
setSize(30+0,30+50);
image=element.jLoadImage(element.jGetSourcePath()+"image.gif");

setPin(0, ExternalIF.C_VARIANT, ExternalIF.PIN_OUTPUT);
setPin(1, ExternalIF.C_VARIANT, ExternalIF.PIN_OUTPUT);
setPin(2, ExternalIF.C_VARIANT, ExternalIF.PIN_INPUT);
setPin(3, ExternalIF.C_INTEGER, ExternalIF.PIN_INPUT);
setPin(4, ExternalIF.C_INTEGER, ExternalIF.PIN_INPUT);
setPin(5, ExternalIF.C_BOOLEAN, ExternalIF.PIN_INPUT);
setPin(6, ExternalIF.C_STRING, ExternalIF.PIN_INPUT);
element.jSetPinDescription(0, "out");
element.jSetPinDescription(1, "value");
element.jSetPinDescription(2, "in");
element.jSetPinDescription(3, "columns");
element.jSetPinDescription(4, "rows");
element.jSetPinDescription(5, "read");
element.jSetPinDescription(6, "look");

element.jSetResizable(true);
element.jSetResizeSynchron(true);
}

public void initInputPins()
{
in= (VSObject)element.getPinInputReference(2);
col= (VSInteger)element.getPinInputReference(3);
row= (VSInteger)element.getPinInputReference(4);
read= (VSBoolean)element.getPinInputReference(5);
look= (VSString)element.getPinInputReference(6);
if (col==null) col=new VSInteger(0);
if (row==null) row=new VSInteger(0);
if (read==null) read=new VSBoolean(false);
if (look==null) look=new VSString();
}

public void initOutputPins()
{
out=element.jCreatePinDataType(0);
element.setPinOutputReference(0,out);

value=element.jCreatePinDataType(1);
element.setPinOutputReference(1,value);
}

public void checkPinDataType()
{
boolean pinIn=element.hasPinWire(2);

int dt=element.C_VARIANT;

if (pinIn==true) dt=element.jGetPinDrahtSourceDataType(2);

element.jSetPinDataType(2,dt);
element.jSetPinIO(2, element.PIN_INPUT);

element.jSetPinDataType(0,dt);
element.jSetPinIO(0, element.PIN_OUTPUT);

if (dt==element.C_ARRAY2D_STRING)
{
element.jSetPinDataType(1,element.C_STRING);
element.jSetPinIO(1, element.PIN_OUTPUT);
}
if (dt==element.C_ARRAY2D_BOOLEAN)
{
element.jSetPinDataType(1,element.C_BOOLEAN);
element.jSetPinIO(1, element.PIN_OUTPUT);
}
if (dt==element.C_ARRAY2D_INTEGER)
{
element.jSetPinDataType(1,element.C_INTEGER);
element.jSetPinIO(1, element.PIN_OUTPUT);
}
if (dt==element.C_ARRAY2D_BYTE)
{
element.jSetPinDataType(1,element.C_BYTE);
element.jSetPinIO(1, element.PIN_OUTPUT);
}
if (dt==element.C_ARRAY2D_DOUBLE)
{
element.jSetPinDataType(1,element.C_DOUBLE);
element.jSetPinIO(1, element.PIN_OUTPUT);
}
element.jRepaint();
}

 

public void process()
{
if (in==null) return;
out.copyReferenceFrom(in);

if (read.getValue())
{
int c=col.getValue();
int j=1;
//int r=row.getValue();
String lo=look.getValue();

if (in instanceof VS2DString)
{
VS2DString inX=(VS2DString)in;
int r=inX.getRows();
//if (c>=inX.getColumns() || r>=inX.getRows()) element.jException("Out of Bounds!");
for(int i=1; i<r; i++)
{
String val=inX.getValue(j,i);
if (val==lo)
{
val=inX.getValue(c,i);
VSString outValue = (VSString)value;
outValue.setValue(val);
break;
}
}
}
// if (in instanceof VS2DBoolean)
// {
// VS2DBoolean inX=(VS2DBoolean)in;

// if (c>=inX.getColumns() || r>=inX.getRows()) element.jException("Out of Bounds!");
// boolean val=inX.getValue(c,r);

// VSBoolean outValue = (VSBoolean)value;
// outValue.setValue(val);
// }
// if (in instanceof VS2DInteger)
// {
// VS2DInteger inX=(VS2DInteger)in;

// if (c>=inX.getColumns() || r>=inX.getRows()) element.jException("Out of Bounds!");
// int val=inX.getValue(c,r);

// VSInteger outValue = (VSInteger)value;
// outValue.setValue(val);
// }
// if (in instanceof VS2DByte)
// {
// VS2DByte inX=(VS2DByte)in;

// if (c>=inX.getColumns() || r>=inX.getRows()) element.jException("Out of Bounds!");
// byte val=inX.getValue(c,r);

// VSByte outValue = (VSByte)value;
// outValue.setValue(val);
// }
// if (in instanceof VS2DDouble)
// {
// VS2DDouble inX=(VS2DDouble)in;

// if (c>=inX.getColumns() || r>=inX.getRows()) element.jException("Out of Bounds!");
// double val=inX.getValue(c,r);

// VSDouble outValue = (VSDouble)value;
// outValue.setValue(val);
// }
element.notifyPin(1);
}
element.notifyPin(0);
}

}

 


ResponderCitar
Share: