bas7advr.hlp (
Topic list)
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
◄Syntax► ◄Details► ◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
CONST declares symbolic constants for use in place of values.
CONST constantname = expression [,constantname = expression]...
■ The expression can consist of literals (such as 1.0), other
constants, or any of the arithmetic and logical operators except
exponentiation (^). You also can use a single literal string such
as "Error on input." You cannot use string concatenation,
variables, user-defined functions, or intrinsic functions--such as
SIN or CHR$--in expressions assigned to constants.
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's type is determined either by an explicit
type-declaration character or by the type of the expression.
■ 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 non-zero value represents "true"):
TRUE=-1
■ Using constants offers several advantages over using variables for
constant values:
- You need only define constants once for an entire module.
- Constants cannot be inadvertently changed.
- In stand-alone programs, using constants produces faster and
often smaller code than using variables.
- Constants make programs easier to modify.