Declares an enumeration and defines its members.
Enum [ enumerationName ] [ As type ] memberName [ = value ] ... End [ Enum ]
- Optional identifier for the enumeration
- Optional primitive integer data type or a different enumerationName. It determines the range of possible values and the default starting value.
- Required identifier
- Optional constant integer expression
- Completes the Enum statement. Alternatively, you can use End Enum.
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.
Enum fruit apple banana cherry End Enum
Enum more_fruit As fruit peach pear pineapple End Enum