Constants
Constants are predefined values that do not change during program execution.
String Constants
A string constant is a sequence of alphanumeric characters enclosed by
double quotation marks.
These alphanumeric characters can be any of the characters whose ASCII codes
fall within the range 0-255 (except the double quote character (") and
carriage-return/line-feed sequences). This range includes both the actual
ASCII characters (0-127) and the extended characters (128-255).
Numeric Constants
Numeric constants are positive or negative numbers. Numeric constants in
BASIC cannot contain commas. The types and subtypes of constants are
listed below:
Type (subtype) Description
Integer One or more decimal digits (0-9), with an optional sign
(decimal) prefix (+ or -). The range for integer decimal
constants is -32,768 to +32,767.
Integer One or more hexadecimal digits (0-9, a-f, or
(hexadecimal) A-F) with the prefix &H or &h. The range for integer
hexadecimal constants is &h0 to &hFFFF.
Integer One or more octal digits (0-7) with the prefix &O, &o,
(octal) or &. The range for integer octal constants is &o0 to
&o177777.
Long integer One or more decimal digits (0-9), with an optional sign
(decimal) prefix (+ or -) and the suffix &. The range for long
decimal constants is -2,147,483,648 to +2,147,483,647.
Long integer One or more hexadecimal digits (0-9, a-f, or A-F) with
(hexadecimal) the prefix &H or &h and the suffix &. The range for
long hexadecimal constants is &h0& to &hFFFFFFFF&.
Long integer One or more octal digits (0-7) with the prefix &O, &o,
(octal) or & and the suffix &. The range for long octal
constants is &o0& to &o37777777777&.
Fixed point Positive or negative real numbers (numbers containing
decimal points).
Floating point Positive or negative numbers represented in exponential
(single precision) form. A single-precision floating-point constant is an
optionally signed integer or fixed-point number (the
mantissa) followed by the letter E and an optionally
signed integer (the exponent). The constant's value is
the mantissa multiplied by the power of ten represented
by the exponent. Single-precision constants have a
range of -3.37E+38 to 3.37E+38.
Floating point Double-precision floating-point constants have the same
(double precision) form as single-precision floating-point constants, but
use D, rather than E, to indicate the exponent. Double-
precision constants have a range of -1.67D+308 to
1.67D+308.
Single-precision constants
Single-precision numeric constants are stored with 7 digits of precision
(plus the exponent). Double-precision numbers are stored with 15 or 16
digits of precision (plus the exponent).
A single-precision constant is any numeric constant that has one of the
following properties:
- Exponential form denoted by E
- A trailing exclamation mark (!)
- A value containing a decimal point that does not have a D in the
exponent or a trailing number sign (#) and that has fewer than
15 digits
- A value without a decimal point that has fewer than 15 digits
but cannot be represented as a long-integer value
Double-precision constants
A double-precision constant is any numeric constant that has one of the
following properties:
- Exponential form denoted by D
- A trailing number sign (#)
- A decimal point, no E in the exponent or trailing exclamation
mark (!), and more than 15 digits
Symbolic Constants
BASIC provides symbolic constants that can be used in place of numeric or
string values. The following fragment declares two symbolic constants and
uses one to dimension an array:
CONST MAXCHARS% = 254, MAXBUF% = MAXCHARS% + 1
DIM Buffer%(MAXBUF%)
The name of a symbolic constant follows the same rules as a BASIC variable
name. You may include a type-declaration character (%, #, !, or $) in the
name to indicate its type, but this character is not part of the name. For
example, after the following declaration, the names N!, N#, N$, N%, and N&
cannot be used as variable names because they have the same name as the
constant:
CONST N=45
A constant's type is determined either by an explicit type-declaration
character or the type of the expression. Symbolic constants are unaffected
by DEFtype statements.
If you omit the type-declaration character, the constant is given a type
based on the expression. Strings always yield a string constant. With
numeric expressions, the expression is evaluated and the constant is given
the simplest type that can represent it. For example, if the expression
gives a result that can be represented as an integer, the constant is given
an integer type.