User Tools

Site Tools


enum_declare_an_enumeration_.htm
Navigation:  Clarion.Net (Clarion#) > Clarion# Language Extensions > Complex Data Types >====== ENUM (declare an enumeration) ====== Previous pageReturn to chapter overviewNext page

NewCNet.jpg

<;label> ENUM
Item1
'
itemN
END

blk2blue.jpg

ENUM declare an enumeration
item item can use the following forms:
<;name>     ITEM[(initexpression)] (<;name> must start on first position of the line)
Or
    <;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.

blk2blue.jpg

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:

Days ENUM

Sat   ITEM

Sun   ITEM

Mon   ITEM

Tue   ITEM

Wed   ITEM

Thu   ITEM

Fri   ITEM

    END

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:

Days ENUM

     Sat(1)

Sun   ITEM

Mon   ITEM

Tue   ITEM

Wed   ITEM

Thu   ITEM

Fri   ITEM

    END

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>

Example:

EId   ENUM

ID1   ITEM

     ID2(ID1+100)

     END

 CODE

 MESSAGE(EId.ID2) ! refers to ID2 item from EId ENUM (101)

enum_declare_an_enumeration_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1