Index Through Arrays

To dynamically change the array element that your logic references, use tag or expression as the subscript to point to the element. This is similar to indirect addressing in
PLC-5
logic. Use these operators in an expression to specify an array subscript:
TIP:
  • Logix Designer
    allows subscripts that are extended data type tags only, and does not support subscript expressions that have extended data types.
  • All available integer elementary data types can be used as a subscript index. Only use SINT, INT, and DINT tags with operators to create a subscript expression.
Operator
Description
+
add
-
subtract/negate
*
multiply
/
divide
AND
AND
BCD_TO
BCD to integer
NOT
complement
OR
OR
TO_BCD
integer to BCD
SQRT
square root
XOR
exclusive OR
For example:
Definitions
Example
Description
my_list defined as DINT[10]
my_list[5]
This example references element 5 in the array. The reference is static because the subscript value remains constant.
my_list  defined as DINT[10]
position defined as DINT
MOV the value 5 into position
my_list[position]
This example references element 5 in the array. The reference is dynamic because the logic can change the subscript by changing the value of position.
my_list  defined as DINT[10]
position defined as DINT
offset defined as DINT
MOV the value 2 into position
MOV the value 5 into offset
my_list[position+offset]
This example references element 7 (2+5) in the array. The reference is dynamic because the logic can change the subscript by changing the value of position or offset.
TIP:
When entering an array subscript, make sure it is within the boundaries of the specified array. Instructions that view arrays as a collection of elements generate a major fault (type 4, code 20) if a subscript exceeds its corresponding dimension.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.