Function checkbounds, L-force | plc designer – Lenze PLC Designer PLC Designer (R2-x) User Manual

Page 523

Advertising
background image

L-force | PLC Designer

Data types in PLC Designer



DMS 3.2 EN 02/2011 TD29

521

Accessing array components:

Array components are accessed in a two-dimensional array using the following
syntax:

<Field_Name>[Index1,Index2]

Example:

Card_game [9,2]

Note!

If you define a function in your project with the name CheckBounds, you can use it
to check for range overflows in your project (see chapter 'What is what in »PLC
Designer«', 'Components of a project', 'Function')

11.2.2

Function CheckBounds

If you define a function in your project with the name CheckBounds, you can
automatically check for out-of-range errors in arrays. 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.

Advertising