CheckBounds

CheckBounds 1:

If you define a function in your project with the name CheckBounds you can use it to check for range overflows in your project! The name of the function is defined and may have only this identifier. An example of how this function is implemented is shown below:

CheckBounds 2:

The function can cause a significant increase in system load, so it should only be used for testing purposes.

FUNCTION CheckBounds : DINT

VAR_INPUT
    index, lower, upper : DINT;
END_VAR

Example of CheckBounds function implementation:

IF index<lower THEN
    CheckBounds := lower;
ELSIF index>upper THEN
    CheckBounds := upper;
ELSE
    CheckBounds := index;
END_IF

The following typical program for testing the CheckBounds function goes beyond the boundaries of a defined array. The CheckBounds functions makes sure that the value TRUE is not assigned to the position A[10], but rather to the upper area boundary A[7] which is still valid. Therefore, the CheckBounds function can be used to correct extensions beyond array boundaries.

CheckBounds 3: