Repository navigation
Enumvalue
Paul Squires edited this page Nov 30, 2026
·
1 revision
Home › Miscellaneous Keywords › EnumValue
Returns an enum's i-th constant, counting from 0 in declaration order.
result = enumvalue( enumtype, i )-
enumtype: the name of anEnumtype, qualified if it is in a namespace (Ns.Inner). -
i: the position of the constant, from 0 toenumcount( enumtype ) - 1.
The constant at position i, as a value of enumtype.
enumvalue and enumcount walk every constant of an enum in the order they are declared, including constants that share a value and enums whose values are not consecutive.
- With a constant
ithe call folds to the constant itself, and aniout of range is a compile-time error (TKO1273). - With a variable
i, under-exx(or-earray) aniout of range stops the program with run-time error 6, as an array index out of bounds does. Without the check the result is not meaningful. - The first argument must be an enum type, not a value of one (TKO1272).
enum Colour
RED = 1
GREEN = 2
BLUE = 4
PRIMARY = 1
end enum
for i as int32 = 0 to enumcount( Colour ) - 1
print i, enumvalue( Colour, i ), enumname( enumvalue( Colour, i ) )
next 0 1 RED
1 2 GREEN
2 4 BLUE
3 1 RED
PRIMARY is the fourth constant, and its value is RED's, so enumname names it RED, the first declared.
Reading a name back into a value is the same loop:
enum Level
Debug, Info, Warn, Error_
end enum
function ParseLevel( byref s as string, byref out_ as Level ) as boolean
for i as int32 = 0 to enumcount( Level ) - 1
if lcase( enumname( enumvalue( Level, i ) ) ) = lcase( s ) then
out_ = enumvalue( Level, i )
return true
end if
next
return false
end function
dim as Level lv
print ParseLevel( "warn", lv ), lv, enumname( lv )
print ParseLevel( "loud", lv )true 2 Warn
false
-
Not a reserved word. A procedure, variable or other symbol of your own named
enumvaluewins, and the built-in is then out of reach in that scope. -
enumvalueis a tiko addition.
Category: Miscellaneous Keywords Kind: function
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Android (experimental)
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Move Semantics
- Match
- Lambdas
- Block Strings
- String Interpolation
- Partial Types
- String Slices
- Array 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)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Hardware
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- tiko test
- tiko doc
- 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