Repository navigation
Enumname
Paul Squires edited this page Nov 30, 2026
·
1 revision
Home › Miscellaneous Keywords › EnumName
Returns the name of the enum constant that has a value, as it is spelled in the declaration.
declare function enumname( byval v as any_enum ) as stringresult = enumname( v )-
v: a value of a namedEnumtype: a constant, a variable or any expression of that type.
The name of the first declared constant whose value equals v, or "" when no constant has that value.
enumname turns an enum value back into its name, so code no longer needs a select case or a macro that lists the names a second time.
- Constants can share a value, so the first one declared wins.
- The name is spelled as in the declaration, in its own case, not upper-cased.
- With a constant argument the call folds to a string literal. With a variable it runs a short search over the constants.
- A value that is not of a named enum is an error (TKO1271), including a plain integer:
enumname( 3 )does not know which enum is meant. Writeenumname( cast( Colour, 3 ) ). - A constant of an enum in a namespace is named without the namespace:
enumname( Ns.Second )is"Second".
Reading a name back into a value is a loop over enumcount and enumvalue; see the example there.
enum Colour
RED = 1
GREEN = 2
BLUE = 4
PRIMARY = 1
end enum
dim as Colour c = BLUE
print enumname( GREEN )
print enumname( c )
print "["; enumname( cast( Colour, 3 ) ); "]" '' no constant has the value 3
print enumname( PRIMARY ) '' 1 is RED's value too, and RED comes firstGREEN
BLUE
[]
RED
-
Not a reserved word. A procedure, variable or other symbol of your own named
enumnamewins, and the built-in is then out of reach in that scope. -
Derive'sToText( )writes an enum field with the same nameenumnamegives, or its decimal value when no constant has it. -
enumnameis 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