Subrange Types
A subrange type is a data type whose value range only covers a subset of a base type.
Only integer types are possible as the base type.
Syntax: <Name> : <Inttype> (<ug>..<og>)
<Name> | Valid IEC identifier |
<Inttype> | Data type of the subrange (SINT, USINT, INT, UINT, DINT, UDINT, BYTE, WORD, DWORD, LINT, ULINT, LWORD). |
<ug> | Lower bound of the range: Constant that must be compatible with the base data type. The lower bound itself is included in this range. |
<og> | Upper bound of the range: Constant that must be compatible with the base data type. The upper bound itself is included in range. |
Sample:
VAR
nVarA: INT (-4095..4095);
nVarB : UINT (0..10000);
END_VAR
If you assign a value to a subrange type in the declaration or implementation that does not fall within this range (for example nVarA: = 5000), TwinCAT issues an error message.
Note the option to monitor the field bounds of a subrange type at runtime using the implicit monitoring functions CheckRangeSigned and CheckRangeUnsigned. |
See also: