Enum Statement

Declares an enumeration and defines its members.


Usual construct

[ @Open ] Enum [ enumeration_name ] [ Is type ]
    member_name [ = value ]
End [ Enum ]

Bit flag construct

[ @Open ] @Flags Enum enumeration_name Is type
    member_name [ = value ]
End [ Enum ]


Optional – Specifies that the Enum can be extended.
Changes the Enum into a set of bit flags.
A name for the enumeration
Optional in the usual construct
Necessary with @Open and the bit-flag construct
A primitive integer data type or a different enumeration_name. It determines the range of possible values and the default starting value.
Optional in the usual construct
Necessary in the bit-flag construct
Necessary name
Optional constant integer expression
Completes the statement. You can also 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 compiler can guarantee that each member is unique.

Usual construct

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.

Bit-flag construct

The bit-flag construct closely resembles the usual construct, but has important differences. Normal enumerations can only be assigned and compared. But flags can be manipulated using the logical operators: And, Or, Xor, and Not.

Each uninitialized member is given the value that corresponds to the least significant bit not used at that point. The first member thus has a default value of one, the second is 2, the third is 4, the fourth is 8, etc.

A type_name is commonly one of the primitive integer types: Int8, UInt8, Int16, UInt16, Int32, UInt32, Int, UInt, Int64, UInt64, Int128, or UInt128.

A member can be given any value in the range of type. Attempting to initialize a member with a value outside of the range results in a compiler error. Members can have duplicate values; however, the names within a set of flags must be unique.

If type is the name of another bit field, the current statement represents an extension to the flags. The range of an extension is the same as its base.

Changes in syntax with @Option

There are four areas where you can change the syntax of the statement:

See @Option Directive for more information.


Listing 1

@Open Enum fruit
End Enum

Listing 2: Extending an enumeration

Enum more_fruit Is fruit
End Enum

Listing 3: A set of bit flags

@Flags Enum days Is UInt8
End Enum

Dim weekend = days.Sat Or days.Sun

See also