Enum Statement

Declares an enumeration and defines its members.

Syntax

Enum [ enumerationName ] [ Is type ]
    memberName [ = value ]
    ...
End Enum

Parts

enumerationName
Optional identifier for the enumeration
type
Optional primitive integer data type or a different enumerationName. It determines the range of possible values and the default starting value.
memberName
Required identifier
value
Optional constant integer expression
End Enum
Terminates the Enum block.

Remarks

An enumeration is a tightly coupled collection of numeric constants. They can make code easier to read and modify by not relying on arbitrary literals scattered throughout the code. In most cases, there is no need to explicitly set a member's value. The language can guarantee that each member is unique.

If an enumeration is not extending an existing one and the first member is not given a value explicitly, its value defaults to zero. Members of an enumeration can be positive or negative. Members can have the same value; however, the names within an enumeration must be unique.

If type is an existing enumeration, the new one is an extension of the pre-existing enumeration. As such, the default starting value is the value of the last member of the pre-existing enumeration plus one.

Examples

Listing 1
Enum fruit
    apple
    banana
    cherry
End Enum

Listing 2: Extending an enumeration
Enum more_fruit Is fruit
    peach
    pear
    pineapple
End Enum

See also