Enum
Declares an enumerated type.
Syntax
`
Enum [typename [ Explicit ] ]
symbolname [= expression] [, ...]
...
End Enum
`
Parameters
`typename`
Name of the `Enum`
`symbolname`
Name of the constant
`expression`
A constant expression
`Explicit`
Requires that symbols must be explicitly referred to by `typename.symbolname`
Description
`Enum`, short for enumeration, declares a list of symbol names that correspond to discrete values. If no initial value is given, the first item will be set to `0`. Each subsequent symbol has a value one more than the previous unless `expression` is given.
Symbols may be each on their own line, or separated on a single line by commas.
An `Enum` is a useful way of grouping together a set of related `Const`ants. A symbol can be accessed like a constant, e.g: `a = symbolname`. But if the name clashes with another symbol, it must be resolved using `typename.symbolname`. This resolution method is always required if you make the enum `Explicit`.
A non-`Explicit` `Enum` declared inside an `Extern ... End Extern` block will add its constants to the parent namespace directly, as in C, instead of acting as a namespace on its own. It disallows the `typename.symbolname` style of access, and the constants may conflict with other symbols from the parent namespace.
An `Enum` can be passed as a user defined type to `Overload`ed operator functions.
Example
`
Enum MyEnum
option1 = 1
option2
option3
End Enum
Dim MyVar As MyEnum
MyVar = option1
Select Case MyVar
Case option1
Print "Option 1"
Case option2
Print "Option 2"
Case option3
Print "Option 3"
End Select
`
Dialect Differences

- Explicit Enum not available in the -lang qb dialect unless referenced with the alias `__Explicit`.

Differences from QB

- New to FreeBASIC

See also

- `Const`
- `Operator`