If you define a function in your project with the name CheckBounds, you can automatically check for out-of-range errors in arrays⮫ “ARRAY”. The name of the function is fixed and can only have this designation.
Example for the function CheckBounds:
FUNCTION CheckBounds : DINT VAR_INPUT index, lower, upper: DINT; END_VAR IF index < lower THEN CheckBounds := lower; ELSIF index > upper THEN CheckBounds := upper; ELSE CheckBounds := index; END_IF
The following sample program for testing the CheckBounds function exceeds the bounds of a defined array. The CheckBounds function allows the value TRUE to be assigned, not to location A[10], but to the still valid range boundary A[7] above it. With the CheckBounds function, references outside of array boundaries can thus be corrected.
Test program for the function CheckBounds:
PROGRAM PLC_PRG VAR a: ARRAY[0..7] OF BOOL; b: INT:=10; END_VAR a[b]:=TRUE;




NOTICE

The CheckBounds-function provided by the Check.Lib library is just a sample solution! Before using that library module check whether the function is working in your sense, or implement an appropriate function directly as a POU in your project.