Skip to main content

Subrange type

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

Syntax in the declaration:

<variabel name> : <integer type> ( <lower index limit> .. <upper index limit> )

<variable name>

Valid IEC identifier

For more information, see: Rules and recommendations for Identifier Designation

<integer data type>

Integer basic data type for the subrange

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

<lower index limit>

Constant for the lower limit of the area which has to be compatible with the basic data type

The lower limit itself is included in this range.

<upper index limit>

Constant for the upper limit of the area which has to be compatible with the basic data type

The upper limit is also included in this range.

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 part that is not within this range, then CODESYS issues an error message.

i:=5000 //Results in an error message

Tip

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.