Lookup in table ar array (SCL step7)

BNA

Member
Join Date
Sep 2003
Location
Give
Posts
117
Hi'

I am trying to make a "lookup" in an table I have created in an array.

My tabel looks like this:

0,920 21,75 200,1 0,00047
0,910 24,99 227,4 0,00052
0,900 28,33 255,0 0,00057

Now I would like to search for lets say 0,910 and retun the values in the next 3 collums : 24,99 227,4 and 0,00052.

I have tried with the "for" instruction, with out any luck.

Any ideas ?

/Brian
 
Example coding:

Code:
DATA_BLOCK DB1
    STRUCT
    Column1:ARRAY[1..10] OF REAL;
    Column2:ARRAY[1..10] OF REAL;
    Column3:ARRAY[1..10] OF REAL;
    Column4:ARRAY[1..10] OF REAL;
    END_STRUCT
BEGIN
Column1[1]:=0.090;
Column1[2]:=0.091;
Column1[3]:=0.092;
Column1[4]:=0.093;
Column1[5]:=0.094;
Column1[6]:=0.095;
Column1[7]:=0.096;
Column1[8]:=0.097;
Column1[9]:=0.098;
Column1[10]:=0.099;
Column2[1]:=0.290;
Column2[2]:=0.291;
Column2[3]:=0.292;
Column2[4]:=0.293;
Column2[5]:=0.294;
Column2[6]:=0.295;
Column2[7]:=0.296;
Column2[8]:=0.297;
Column2[9]:=0.298;
Column2[10]:=0.299;
Column3[1]:=0.390;
Column3[2]:=0.391;
Column3[3]:=0.392;
Column3[4]:=0.393;
Column3[5]:=0.394;
Column3[6]:=0.395;
Column3[7]:=0.396;
Column3[8]:=0.397;
Column3[9]:=0.398;
Column3[10]:=0.399;
Column4[1]:=0.490;
Column4[2]:=0.491;
Column4[3]:=0.492;
Column4[4]:=0.493;
Column4[5]:=0.494;
Column4[6]:=0.495;
Column4[7]:=0.496;
Column4[8]:=0.497;
Column4[9]:=0.498;
Column4[10]:=0.499;
END_DATA_BLOCK

FUNCTION_BLOCK FB1
VAR_INPUT
rSearchValue:REAL;
END_VAR
VAR_OUTPUT
rCol2:REAL;
rCOl3:REAL;
rCol4:REAL;
end_var
VAR
i:int;
end_var
FOR i:=1 TO 10 DO
 IF DB1.Column1[i]=rSearchValue THEN 
   rCol2:=DB1.Column2[i];
   rCol3:=DB1.Column3[i];
   rCol4:=DB1.Column4[i];
 END_IF;
END_FOR;
END_FUNCTION_BLOCK
FUNCTION_BLOCK FB2
VAR
fbS:fb1;
rResult2:REAL;
rResult3:REAL;
rResult4:REAL;
END_VAR
fbs(rSearchValue:=0.094);
rResult2:=fbs.rCol2;
rResult3:=fbs.rCol3;
rResult4:=fbs.rCol4;
END_FUNCTION_BLOCK
DATA_BLOCK DB2  FB2
BEGIN
END_DATA_BLOCK

ORGANIZATION_BLOCK OB1
VAR_TEMP
    // Reserved
    info : ARRAY[0..19] OF BYTE;
    // Temporary Variables
END_VAR
FB2.DB2(); 
END_ORGANIZATION_BLOCK
 
Thank you, what a fantastic solution, this absolutley does the trick.

I get what is going on in FB1, but i'm not sure what the code in FB2 and OB1 does ?

FUNCTION_BLOCK FB2
VAR
fbS:fb1;
rResult2:REAL;
rResult3:REAL;
rResult4:REAL;
END_VAR
fbs(rSearchValue:=0.094);
rResult2:=fbs.rCol2;
rResult3:=fbs.rCol3;
rResult4:=fbs.rCol4;
END_FUNCTION_BLOCK
DATA_BLOCK DB2 FB2
BEGIN
END_DATA_BLOCK
ORGANIZATION_BLOCK OB1
VAR_TEMP
// Reserved
info : ARRAY[0..19] OF BYTE;
// Temporary Variables
END_VAR
FB2.DB2();
END_ORGANIZATION_BLOCK


/Brian
 

Similar Topics

Hey Guys.. Here's my problem. I have an array of 9 characters, a "part number". I need to compare this array to another part number that is...
Replies
10
Views
6,607
Hello all, I am working on a project with an s7-1200 and I am controlling three stepper motors using this controller. I will be receiving input...
Replies
5
Views
2,411
Hi All, So I am using an Automation Direct BRX PLC (Do-More Designer 2.5), in which I need to calculate the Log Inactivation of Giardia. I am...
Replies
5
Views
3,606
Hello all, I need to do something and I'm not sure if it's possible.. some aspects I know how to do but not quite on the scale of this project. A...
Replies
5
Views
2,544
Hi guys, I want to program map tracking using factorytalk view site edition ver9. I have map which shows vehicle on it, the vehicle location...
Replies
1
Views
2,022
Back
Top Bottom