Sign in to follow this  
Followers 0

Solved - Cx-Programmer Ladder Array Index

1 post in this topic

Array A INT[32]
Array Index B INT
Destination C INT


I am trying to move an Array (A) Element (A[2]) using a symbol (B) in ladder into a destination symbol (C)

C = A [ B ]



ERROR: Array Index of Operand 1 out of range at rung 1 ( 6, 0 ). 


The documentation suggests that it is possible, but I am unsure if there is something I am doing incorrectly.


Note* Fixed indexing works with no errors


Is there another method to accomplish this?


CX- Programmer: Verion 9.74

Update 1:

If I go online to the PLC It does look like the array look up is working. Is the issue with the mov block?


Update 2:

I changed the memory locations which has caused a different error to appear. This error is clearer but does not explain the manual excerpt I posted further up

ERROR: Only the constant can be specified for the index of the array.  at rung 5 ( 6, 0 ). 


Update 3: Solution 1

I managed to hack together a proof of concept using pointers and indirect offsets 

Update 4: Solution 2

For some strange reason things work as expected inside of the function blocks so I made one where the array is In-Out and with an input and output respectively.

Note* External reference to pointers inside of the function block produced an error.


Function block Logic



Update 5: Solution 3

Now I feel like I am going crazy, I tried just the original code again and it works... I have no idea why and if it was not for all the documentation I would be lost as to why it works now...


Update 6: Conclusion

It seems to have array indexing work the array index must exist in the D Memory Block. The reason it did not work above is because I somehow had a MOVR block when I tested after moving all the variables to the D Memory Block. I hope this journey helps someone else :)

Edited by dutoitj3
Further investigation
1 person likes this

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0