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. You can use these operators in an expression to specify an array subscript:
Operator | Description |
---|---|
+ | add |
- | subtract/negate |
* | multiply |
/ | divide |
AND | AND |
FRD | BCD to integer |
NOT | complement |
OR | OR |
TOD | integer to BCD |
SQR | 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. |
Make sure any array subscript you enter 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