Seeking help: "Index value exceeds the bounds of the array dimension" error in PLCnext Engineer

Hello everyone,
I’m currently facing an issue in PLCnext Engineer where I encounter an " Index value exceeds the bounds of the array dimension" error when attempting to access the first index [0] of an array named SENSOR_DATA. This index is crucial as it holds the temperature data from a holding register. I also access indices for EC [2] and TDS [4], where there are no issues.

ArrayDimensions.png
Here’s the situation:
I am able to access indexes 1 to 125ModbusFB.pngDataTypes.png
* without any issues.
* Any attempt to access index 0 or any index above 125 results in the aforementioned error.
* This error occurs even though index 0 should theoretically be valid and is essential for processing the temperature data.
I’ve attached screenshots showing my list of variables, the applied function blocks, and the specific snippet of Structured Text where the error is reported. I am puzzled because accessing the first element of an array should be straightforward. Although this is my first time working with Modbus protocols, the error doesn’t seem to be directly caused by the Modbus configuration; nonetheless, I’m unsure why it’s considered out of bounds.
Could anyone shed some light on what might be causing this issue or how to resolve it? Any suggestions or insights would be greatly appreciated!
Thanks in advance for your help!

Hi!
You declare variableSENSOR_DATA as arrModbus2_W_1_125 datatype.
And this datatype array dimension declared as [1..125] of WORD. So there is no item with index [0].

In this case first register you define as start register of reading gap from the field device will correspond to SENSOR_DATA[1] register in FC3.
BR

Thank you so much for your quick and clear response!
You’ve pinpointed the issue exactly. I misunderstood the array indexing, thinking it started at 0, but as you’ve correctly noted, SENSOR_DATA is defined from 1 to 125. This explains why I was encountering the “Index value exceeds the bounds of the array dimension” error when attempting to access SENSOR_DATA[0].
I will adjust my code to use SENSOR_DATA[1] for temperature, SENSOR_DATA[3] for EC, and SENSOR_DATA[5] for TDS, aligning with the correct indices. This resolved the error I was facing and should fetch the correct data.
Thanks again for your help. I really appreciate it!
Best regards

Also make sure that you never use indexes outside the bounds in runtime as the PLC program will stop.
it is an easy mistake to do when using variables for index.