Accessing the ARRAY data type and ARRAY elements

If you want to declare a variable based on an array data type (this is declaring an array variable), enter the name of the array data type (e.g. myType) as data type within the declaration of variables. As alternative you may enter the array specification directly in the declaration of the variable (this is declaring an array variable as well); see var2 and var3 in the following example.

If you want to assign an array variable to another array variable, both must be based on the same data type and the same index subrange. In case of a STRING base data type, the length must be equal as well.
If you want to use array element in assignments, enter the name of the variable or of the function block (e.g. var1 or TONArr1) and the array subscript (e.g. 2) enclosed in brackets (e.g. var1[2] or TONArr1[30]). In case of a multi-dimensional array element, separate the array subscripts by the character , (e.g. var6[1,2]). As enhancement to the →IEC-standard, it is also possible to enter each of the array subscripts within [] behind each other (e.g. var6[1][2]).
You can assign an array element to another array element, if both are based on the same data types.

You may enter an →expression as array subscript but it has to return a value of the →data type DINT. The entered array subscript must be part of the index subrange. If you enter array subscripts as →constant (e.g. var1[2]), invalid array subscripts are automatically highlighted as errors by logi.CAD 3.

If you are using →variables and/or operators for the array subscripts (e.g. var1[3+3]), these specifications are not validated when they are entered in the ST-editor. The array subscript is calculated when the application is executed. If the calculated array subscript is outside the index subrange, the exceeded limit is used when the application is executed (hence: x, if array subscript < x, and y, if array subscript > y). Moreover, the output ENO of the embracing →POU is additionally set to value FALSE (or an equivalent).

logi.cals recommends you to add code to your application (e.g. IF-statements) so that array subscripts outside the index subranges are detected.

Examples
VAR
var1: myType; (* 'myType' has been declared as array data type: 'ARRAY [1..9] OF INT := [1, 2, 3]' *)
var2: ARRAY [1..9] OF INT := [9(1)];
var3: ARRAY [1..2] of BOOL := [2(TRUE)];
var4: inputData; (* 'inputData' has been declared as array data type: 'ARRAY [0..1] OF BOOL := [2(TRUE)]' *)
var5: ARRAY [1..2] of WORD;
var6: ARRAY [1..2, 1..3] OF INT := [2([3(25)])];
var7: ARRAY [1..2, 1..3, 1..4] OF INT := [2([3([4(15)])])];
END_VAR
 
(* assignments: ARRAY variable to ARRAY variable *)
var1 := var2; (* OK, because 'var1' and 'var2' are based on the same data type and the same index subrange *)
var5 := var3; (* error, because 'var5' and 'var3' are not based on the same data type *)
var3 := var4; (* error, 'var3' and 'var4' are based on the same data type but not on the same index subrange *)
 
(* assignments with array element *)
var1[2] := 5; (* OK, because '5' is allowed for data type 'INT' *)
var3[1] := FALSE; (* OK, because 'FALSE' is allowed for data type 'BOOL' *)
var4[1] := 5; (* error, because '5' is not allowed for data type 'BOOL' *)
var1[13] := 5; (* error, because subscript '13' is outside of the index subrange '1..9' *)
var1[0] := 5; (* error, because subscript '0' is outside of the index subrange '1..9' *)
var3[1] := var4[1]; (* OK, because 'var3' and 'var4' are based on the same data type *)
var3[1] := var4[6]; (* error, because subscript '6' for 'var4' is outside of the index subrange '0..1' *)
var1[2] := var3[2]; (* error, because 'var1' is of type 'BOOL' and 'var3' of type 'INT'. 'BOOL' cannot be converted implicitly to 'INT'. *)
var5[1] := var3[1]; (* OK, because 'var3' is of type 'BOOL' and 'var5' of type 'WORD'. 'BOOL' can be converted implicitly to 'WORD'. *)
var1[3+3] := 5; (* Input is possible, execution is OK. Reason: '3+3' produces the valid subscript '6'. *)
(* Recommended: Insert additional code that checks whether an invalid subscript might result. *)
var1[4*3] := 5; (* Input is possible, but execution is done by using 'var1[9]' (instead of 'var1[12]'). Reason: '4*3' produces the invalid subscript '12'. *)
(* Moreover, 'ENO' of the embracing POU is set to 'FALSE' during the execution. *)
(* Recommended: Insert additional code that checks whether an invalid subscript might result. *)
(* Assignment to an array element with 2 dimensions *)
var6[1,2] := 5; (* assigning '5' to the element 'var6[1,2]' *)
var6[2][1] := 5; (* assigning '10' to the element 'var6[2,1]' *)
(* Assignment to an array element with 3 dimensions *)
var7[1,2,3] := 5; (* assigning '5' to the element 'var7[1,2,3]' *)
var7[2][1][4] := 5; (* assigning '10' to the element 'var7[2,1,4]' *)
 
(* The assignments to an array element with 4 dimensions are similar to the assignments to an array element with 3 dimensions. *)

Displayed array elements

The display for an array variable in the Instances view is restricted to the base type. If you wish to insert array elements into the Values of Variables view in order to monitor its values, but these array elements are not provided in the Instance view, just drag the base type into the Values of Variables view and modify the inserted item (complete it by the requested array index).