Access to Variables in Arrays, Structures, and Blocks
Access to array elements
Syntax
<Name der Arrayvariablen> [ <kommaseparierte Liste der Dimensionsindizes> ]
| Sample: More information: Assigning identifiers |
| One index per dimension, so that one element of the array is identified Sample: The index is valid from the index minimum to the index maximum. Sample: |
Samples
One-dimensional array with ten components
// Declaration
VAR
aSample : ARRAY[0..9] OF INT;
nVar : INT;
END_VAR
// Implementation
nVar := aSample[2];
Two-dimensional array with two times two components
//Declaration
VAR
aCardGame : ARRAY[1..2, 3..4] OF INT;
nVar1 : INT;
END_VAR
//Implementation
nVar1 := aCardGame[1, 3];
More information: ARRAY
Access to structure components
Syntax
<Name der Strukturvariablen>.<Name der Komponente>
| Sample: More information: Assigning identifiers |
| Sample: |
Samples
// Declaration type
TYPE ST_POLYGONLINE :
STRUCT
aStart : ARRAY[1..2] OF INT := [-99, -99];
aPoint1 : ARRAY[1..2] OF INT;
aPoint2 : ARRAY[1..2] OF INT;
aPoint3 : ARRAY[1..2] OF INT;
aPoint4 : ARRAY[1..2] OF INT;
aEnd : ARRAY[1..2] OF INT := [99, 99];
END_STRUCT
END_TYPE
//Declaration structure variable
VAR
sPolygon : ST_POLYGONLINE;
nPoint : INT;
END_VAR
//Implementation
nPoint := sPolygon.aPoint1[1];
More information: Structure
Access to variables in programming blocks
Syntax
<POU Name>.<Variablenname>
| Name of a function block instance ( Sample: More information: Assigning identifiers |
| POU variable Sample: |
Samples
FUNCTION_BLOCK FB_SAMPLE
VAR_INPUT
bStart : BOOL;
END_VAR
VAR_OUTPUT
END_VAR
VAR
nState : INT;
END_VAR
IF bStart = TRUE THEN
nState := 1;
END_IF
PROGRAM MAIN
VAR
fbSample : FB_Sample;
END_VAR
fbSample();
fbSample.bStart := TRUE;
More information: Object Function block, Object Program
See also: