Repository navigation
Enum
Home › User Defined Types › Enum
Declares an enumerated type.
Enum [typename [ Explicit ] ]
symbolname [= expression] [, ...]
...
End Enumtypenamesymbolnameexpressiontypename.symbolname
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 Constants. 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.
Enum can not contain any member procedure or member data (only symbols), but it can be included (named or unnamed) in a Type by having.
An Enum instance can be passed, as any user defined instance, to a procedure (including for the definition of Overloaded operators).
The size of an Enum instance will be always that of an Integer (no matter how many defined symbols are just declarations for the compiler assignment).
- Explicit Enum not available in the -lang qb dialect unless referenced with the alias
__Explicit.
- New to FreeBASIC
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 SelectYou can reference formerly declared symbol names within the same enum:
Enum MyEnum
option1 = 1
option2
option3
__
MAX_VALUE = __ -1
End Enum
Print "Option #1:", MyEnum.option1
Print "Option #2:", MyEnum.option2
Print "Option #3:", MyEnum.option3
Print "Max Value:", MyEnum.MAX_VALUEOutput:
Option #1: 1
Option #2: 2
Option #3: 3
Max Value: 3Category: User Defined Types
Kind: keyword
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing