L-force | plc designer – Lenze PLC Designer PLC Designer (R2-x) User Manual
Page 531

L-force | PLC Designer
Data types in PLC Designer
DMS 3.2 EN 02/2011 TD29
529
Example:
In the case of a variable belonging to a signed subrange type (like i, above), the
function CheckRangeSigned is called; it could be programmed as follows to trim a
value to the permissible range:
FUNCTION CheckRangeSigned : DINT
VAR_INPUT
value, lower, upper: DINT;
END_VAR
IF (value < lower) THEN
CheckRangeSigned := lower;
ELSIF(value > upper) THEN
CheckRangeSigned := upper;
ELSE
CheckRangeSigned := value;
END_IF
In calling up the function automatically, the function name CheckRangeSigned is
obligatory, as is the interface specification: return value and three parameters of type
DINT
When called, the function is parameterized as follows:
• value: the value to be assigned to the range type
• lower: the lower boundary of the range
• upper: the upper boundary of the range
• Return value: this is the value that is actually assigned to the range type
An assignment i:=10*y implicitly produces the following in this example:
i := CheckRangeSigned(10*y, -4095, 4095);
Even if y for example has the value 1000, then i still has only the value 4095 after this
assignment.