Subrange Types

A subrange type is a data type whose value range is a subset of a base type.

Syntax for the declaration:

<name> : <int type> (<lower limit>..<upper limit>);
<name> valid IEC identifier
<int type>

data type of the subrange

(SINT, USINT, INT, UINT, DINT, UDINT, BYTE, WORD, DWORD, LINT, ULINT, LWORD).

<lower limit> Lower limit of the range: constants that have to be compatible with the basic data type. The lower limit is also included in this range.
<upper limit> Upper limit of the range: constants that have to be compatible with the base data type. The upper limit is also included in this range.

Examples:

VAR
 i : INT (-4095..4095);
 ui : UINT (0..10000);
END_VAR

If you assign a value to a subrange type in the declaration or implementation section that is not within this range (example: i:=5000), then CODESYS issues an error message.

Note

Please note: In runtime mode, it is possible to monitor the range limits of a subrange type by using the implicit monitoring functions CheckRangeSigned and CheckRangeUnsigned.

See also