V4005¶
- Code
V4005
- Message
Array index out of bounds
The program attempted to access an array element with an index that is outside the valid range. The index must be between the declared lower and upper bounds of the array.
Example¶
The following code will generate error V4005:
PROGRAM Main
VAR
values : ARRAY[1..5] OF INT;
result : INT;
END_VAR
result := values[6]; (* Error: index 6 is out of bounds for ARRAY[1..5] *)
END_PROGRAM
The array values has valid indices 1 through 5, but index 6 is outside
that range.
To fix this error, ensure the index is within the declared bounds of the array:
PROGRAM Main
VAR
values : ARRAY[1..5] OF INT;
i : INT;
result : INT;
END_VAR
i := 3;
IF i >= 1 AND i <= 5 THEN
result := values[i];
END_IF;
END_PROGRAM
Think IronPLC is wrong about this?
If you believe this diagnostic is incorrect, open an issue on GitHub with a small sample that demonstrates the problem.