|Navigation: Clarion.Net (Clarion#) > Clarion# Language Extensions > Complex Data Types >====== ENUM (declare an enumeration) ======|
|ENUM||declare an enumeration|
|item||item can use the following forms:|
|<;name> ITEM[(initexpression)]||(<;name> must start on first position of the line)|
|<;name> [(initexpression)]||(<;name> must not start on first position of the line)|
|name||A string constant that identifies the item name.|
|Initexpression||a constant expression, that evaluates to a LONG value. The base type for the enumeration is LONG. If initexpression is present then the value of the item is the value of the expression, otherwise the value equals to value of the previous item incremented by 1. The default value for the first item is 0.|
ENUMs are used to declare .Net's enumerations types The enum keyword is used to declare an enumeration, a distinct type consisting of a set of named constants called the enumerator list. Every item can be any integral type except CHAR.
By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1. For example:
In this enumeration, Sat is 0, Sun is 1, Mon is 2, and so forth. Enumerators can have initializers to override the default values. For example:
In the above ENUM, the sequence of elements is forced to start from 1 instead of 0.
A variable of type Days can be assigned any value in the range of the underlying type; the values are not limited to the named constants.
To refer to an item of the ENUM in the code the following syntax is used:
<;label of ENUM>.<;name of item>
MESSAGE(EId.ID2) ! refers to ID2 item from EId ENUM (101)