EQUATE statement

Syntax

EQU[ATE] symbol TO expression [ ,symbol TO expression ...]
EQU[ATE] symbol LIT[ERALLY] string [ ,symbol LIT string ...]

Description

In an EQUATE statement, symbol represents the value of expression or string. You can use the two interchangeably in the program. When the program is compiled, each occurrence of symbol is replaced by the value of expression or string. The value is compiled as object code and does not have to be reassigned each time the program is executed.

You can define multiple symbols in a single EQUATE statement. symbol cannot be a number.

You can define symbol only once. Any subsequent EQUATE state generates a compiler error because the compiler interprets the symbol before the statement is parsed.

If you use TO as a connector, the object can be any BASIC expression. If you use LIT or LITERALLY as a connector, the object must be a literal string.

RAID does not recognize EQUATE symbols. You must use the object value in RAID sessions.

There is no limit on the number of EQUATE statements allowed by the BASIC compiler, except that of memory.

If symbol is the same as the name of a BASIC function, the function is disabled in the program. If a statement exists with the same name as a disabled function, the statement is also disabled.

Examples

In the following example, A is made equivalent to the string JANE:

JANE="HI"
EQUATE A TO "JANE"

Next, B is made equivalent to the variable JANE:

EQUATE B LIT "JANE"
PRINT "A IS EQUAL TO ":A
PRINT "B IS EQUAL TO ":B

This is the program output:

A IS EQUAL TO JANE
B IS EQUAL TO HI

In the next example COST is made equivalent to the value of the expression PRICE*QUANTITY:

EQUATE COST LIT "PRICE * QUANTITY"
PRICE=3;QUANTITY=7
PRINT "THE TOTAL COST IS $": COST

This is the program output:

THE TOTAL COST IS $21

The next example shows an EQUATE statement with multiple symbols:

EQUATE C TO "5",
   D TO "7",
   E LIT "IF C=5 THEN PRINT 'YES'"
PRINT "C+D=": C+D
E

This is the program output:

C+D=12
YES