<< Click to Display Table of Contents >> Navigation: ThinBASIC Core Language > Data types and variables > Enum ... End Enum |
Description
Creates a group of logically related constant equates.
Syntax
Enum EnumName [SINGULAR] [BITS]
MemberName1 [= Value]
MemberName2 [= Value]
[...]
End Enum
Returns
None
Parameters
Remarks
thinBasic allows you to refer to integral numeric constants by name. These names are called equates, and are visible throughout your program. If you need a set of equates which are logically related, you can define them as a group in an enumeration. This provides meaningful names for the enumeration, its members, and therefore the name by which it is referenced.
When an equate is created in an enumeration, its name is composed of the enumeration name, a period (.), and then the member name. For example:
ENUM abc
count = 7
END ENUM
In the above example, the equate is referenced as abc.count, and returns the value seven (7).
Each member of an enumeration may be assigned a specific integral value (in the range of a 64-bit quad integer) by using the optional [=value] syntax.
If the [=value] option is omitted, each member of the enumeration is assigned an integral value in sequence beginning with the value 0.
If one or more equates are assigned an explicit value, equates which follow are assigned the next value in the sequence. For example:
ENUM abc
direction
count = 8
scope
END ENUM
In the above example, abc.direction = 0, abc.count = 8, and abc.scope = 9.
BITS (still to be developed)
If the BITS option is included, the members are auto-assigned values suitable for use as a bit mask, increasing as integral powers of two. The first member is auto-assigned the value 0, the next is 1, then 2, 4, 8, 16, etc. If one or more are assigned an explicit value, equates which follow are assigned the next value in the sequence. For example:
ENUM abc BITS
direction = 1
count = 8
scope
END ENUM
In the above example, abc.direction = 1, abc.count = 8, and abc.scope = 16.
SINGULAR
If the SINGULAR option is included, the member name is the complete name, without the ENUM name or the period. The equate is referenced by just the member name with a percent (%) pre-pended. For example:
ENUM abc SINGULAR
count = 7
END ENUM
In the above example, the equate would normally be referenced by the compound name abc.count. However, since it includes the SINGULAR option, it is referenced by the simplified name %count.
Restrictions
See also
Examples
'---Declare a global enumerator for script possible errors to be returned
Enum gErrors
AppConfig_LoadError = 10 '---Error during config loading
DB_Connection_Main = 110 '---Error while connecting to Main DB
DB_Connection_Staging = 120 '---Error while connecting to Staging DB
DB_RecordSet_Open_Main = 1110 '---Error while opening recordset on Main DB
DB_RecordSet_Open_Staging = 1120 '---Error while opening recordset on Staging DB
End Enum
'---Will return 120
APP_SetReturnCode( gErrors.DB_Connection_Staging )