Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
CONST Statement Details
◄Summary► ◄Details► ◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
CONST constantname = expression [,constantname = expression]...
Usage Notes
■ If you use a type-declaration character in the name, you can omit the
character when the name is used, as shown in the following example:
CONST MAXDIM% = 250
.
.
.
DIM AccountNames$(MAXDIM)
■ If you omit the type-declaration character, the constant is given a type
based on the expression in the CONST statement. Strings always yield a
string constant. With numeric expressions, the expression is evaluated
and the constant is given the simplest type that can represent the
constant. For example, if the expression gives a result that can be
represented as an integer, the constant is given an integer type.
■ Names of constants are not affected by DEFtype statements such as
DEFINT. A constant type is determined either by an explicit type-
declaration character or by the type of the expression.
See: ◄DEFtype Statements►
■ Constants must be defined before they are referred to. The following
example produces an error because the constant ONE is not defined
before it is used to define TWO (constants are defined from left to
right):
CONST TWO = ONE + ONE, ONE = 1
■ Constants declared in a SUB or FUNCTION procedure are local to the
SUB or FUNCTION. A constant declared outside a procedure is defined
throughout the module. You can use constants anywhere that you would
use an expression.
■ A common programming practice is to use a statement such as the
following (any nonzero value represents "true"):
TRUE = -1
■ Using constants offers several advantages over using variables for
constant values:
• You only define constants once for an entire module
• Constants cannot be inadvertently changed
• Using constants rather than variables produces faster and often more
compact code in stand-alone programs
• Constants make programs easier to modify