free web page builder

### CONSTANTS

Pre-Defined Constants

PI is a double precision shortcut for the constant 3.141592653589793

TRUE is a boolean constant that represents the true condition.

FALSE is a boolean constant that represents the false condition.

Boolean Constants

There are two boolean constants namely TRUE and FALSE which translate to 1 (true) and 0 (false) when converted to other data types. The values TRUE and FALSE values are not case sensitive.

Byte Constants ( 8 Bit Signed Integer)

Byte constants can't be directly defined and have to be created using the BYTE(…) function. Byte Constants contain values from -128 to +127

SUB MAIN

DIM X AS BYTE

X=BYTE(0x80)

PRINT "X=" + STR\$(X)

X= BYTE(127)

PRINT "X=" + STR\$(X)

END SUB

Complex Constants

Complex constants can't be directly defined and have to be created using the COMPLEX(…) function.

SUB MAIN

DIM X AS COMPLEX

X = COMPLEX(3.2, -2.2)

PRINT X

END SUB

Double Constants (64 Bit Double Precision Floating Point Constants)

Double Constants are values that contain a decimal point plus an optional exponent.

9.12 - double precision floating point value

9.12E+1 - exponent is used to move the decimal point one place to the right. Thus 9.12E+1 represents 91.2

9.12e-1 - exponent is used to move the decimal point one place to the left. Thus 9.12e-1 represent 0.912

SUB MAIN

DIM X AS DOUBLE

X=1.234E+2

PRINT "X=" + STR\$(X)

X=-1234.56E-2

PRINT "X=" + STR\$(X)

X=321.1234567890123

PRINT "X=" + STR\$(X)

X=PI

PRINT "X=" + STR\$(X)

END SUB

Float Constants (32 Bit Single Precision Floating Point Constants)

Float Constants are values that contain a decimal point plus an optional exponent. A float constant is distinguished from a double constants by postfixing a F character onto the end of the number.

9.12f - single precision floating point value

9.12E+1f - exponent is used to move the decimal point one place to the right. Thus 9.12E+1 represents 91.2

9.12e-1f - exponent is used to move the decimal point one place to the left. Thus 9.12e-1 represent 0.912

SUB MAIN

DIM X AS FLOAT

X=321.1234f

PRINT "X=" + STR\$(X)

X=1.234E+2f

PRINT "X=" + STR\$(X)

X=-1234.56E-2f

PRINT "X=" + STR\$(X)

END SUB

Integer Constants (32 Bit Signed Integer)

Integer constants are numbers that don't contain a fractional part. An integer constant must be in the range -2147483648 (0x80000000) and 21474836471 (0x7fffffff) inclusive. If the value falls outside this range then it must defined as a long constant.

-25 is an integer constant

0b1010 is an integer constant defined in binary

0377 is an integer constant defined in octal

0x00FF is an integer constant defined in hexadecimal

21474836472 is too big to be an integer constant and it must be defined as a long (21474836472L)

3.142 contains a decimal point and cannot be an integer constant.

Long Constants (64 Bit Signed Integer)

Long constants are the same as Integer constants however they can hold larger values. A long constant must be in the range -9223372036854775808 (0x8000000000000000) and 9223372036854775807 (0x7FFFFFFFFFFFFFFF) inclusive. Long constants are specified by postfixing a L character onto the end of the number.

123L is an long constant.

0b1010L is an long constant defined in binary

0377L is an long constant defined in octal

0X7FFFFFFFFFFFFFFFL is a long constant defined in hexadecimal

Short Constants (16 Bit Signed Integer)

Short constants can't be directly defined and have to be created using the SHORT(…) function. Short Constants contain values from -32768 to +32767

SUB MAIN

DIM X AS SHORT

X=SHORT(123)

PRINT X

X=SHORT(0x8000)

PRINT X

X=SHORT(0x7fff)

PRINT X

END SUB

String Constants

A string constant is defined by a sequence of characters enclosed within double quotes. The actual value of the constant is the sequence of characters without the surrounding double quotes. Any characters can be placed within the double quotes however there are a few that need to be preceded by the backslash ( '\' ) character:-

Use \\ if you want to insert a backslash character in your string.

Use \" if you want to insert a double quote character in your string.

Use \n if you want to insert a newline character in your string.

SUB MAIN

DIM X AS STRING

X="Backslash character=\\"

PRINT "X: " + X

X="Quote Character=\""

PRINT "X: " + X

X="First line\nSecond line"

PRINT "X: " + X

X=STRING(123)

PRINT "X=" + X

END SUB

Variant Constants

Variant constants can't be directly defined and have to be created using the VARIANT(…) function.

SUB MAIN

DIM X AS VARIANT

X = VARIANT(123)

PRINT X

X = VARIANT("XYZ")

PRINT X

END SUB