Navigation:  ThinBASIC Language > Data types and variables >

Numeric Equates

Previous pageReturn to chapter overviewNext page

 

Numeric equates

 

thinBasic allows you to refer to numeric constants by name. Those constant values are called equates.

A numeric equate (constant) must start with % sign.

 

Equates data type

 

Equates declaration has the following syntax:

 

%EquateName = NumericExpression [As NumericDataType]

 

Equal sign is optional, so the above sentence can also be written as:

 

%EquateName NumericExpression [As NumericDataType]

 

Where the optional parameter NumericDataType can be any of the allowed numeric data types: BYTE, INTEGER, WORD, DWORD, LONG, QUAD, SINGLE, DOUBLE, EXTENDED, CURRENCY.

If not NumericDataType is specified, default type will be assumed to be LONG.

 

Binary and hex numbers can be represented indicating &B or &H followed by the relative representation. Examples:

 

%MAXIMUM_D  = &HFFFFFFFF As DWord

%MAXIMUM_L  = &H7FFFFFFF As Long

%MINIMUM_L  = &H80000000 As Long

 

%Normal   = &B000000

%ReadOnly = &B000001

%Hidden   = &B000010

%System   = &B000100

%vLabel   = &B001000

%SubDir   = &B010000

%Archive  = &B100000

 

Hex numbers can be also represented using C notation 0x... followed by the hex representation of the hex value.

Examples:

%MAXIMUM_D  = 0XFFFFFFFF As DWord

%MAXIMUM_L  = 0X7FFFFFFF As Long

%MINIMUM_L  = 0X80000000 As Long

 

Examples

 

Some equate declaration example:

 

%MAXPIECES = 32

%NPARAM    = 3

%NTYPE     = 1

%RANK      = 2

%FILE      = 3

%KING      = 1

%PAWN      = 2

 

%MAXVALUE  = 0.999 AS EXT

%ANYVALUE  = 0.999 AS DOUBLE

 

Restrictions

 

1.Numeric equates name must start with percent sign %
2.Unlike variables, you can use an equate on the left side of an assignment statement only once.
3.If an equate has already been created, subsequent attempts to assign a new value will fail but no error will be generated