|
EQUATE, EQU |
|
|
The EQUATE statement, often abbreviated to EQU, defines a symbolic name to represent a constant or reference to a matrix element.
Format
EQUATE name LITERALLY "string" EQUATE name TO value EQUATE name TO variable EQUATE name TO matrix(index1 {, index2) EQUATE name TO dyn.array<field {, value {, subvalue}}> EQUATE name TO CHAR(seq)
where
The EQUATE statement defines a name that can be used later within the program as a reference to a constant, matrix element, dynamic array element, character value or QMBasic source construct. EQUATE statements are often placed in include records so that the same values can be incorporated into many programs without duplication.
All variants of the EQUATE statement except LITERALLY can alternatively be written using the $DEFINE compiler directive.
EQUATE name LITERALLY "language elements" This form of EQUATE defines a name that is replaced by the language elements. These may be any QMBasic construct and must be enclosed in quotes. The LITERALLY keyword may be abbreviated to LIT.
EQUATE name TO value This form of the EQUATE statement creates a symbolic name that can be used in place of the constant value. The EQUATE statement can be used to eliminate constants for state variables, field positions, etc from the main body of a program. Subsequent changes to the value thus only require a single amendment and recompilation of all programs using name.
EQUATE name TO variable This form of EQUATE defines a synonym for a variable name.
EQUATE name TO matrix(index1 {, index2) This form of EQUATE defines a name by which an element of a dimensioned array can be referenced. The index values must be numeric constants.
EQUATE name TO dyn.array(field {, value {, subvalue}}> This form of EQUATE defines a name by which an element of a dynamic array can be referenced. The index values must be numeric constants. Declaration and dimensionality of the matrix are only checked when a reference to name is encountered during program compilation.
EQUATE name TO CHAR(seq) This form of EQUATE defines a name to represent a character value. It is often used with non-printing characters.
Multiple tokens may be equated on a single line by separating each definition by a comma. For example: EQUATE LOW TO 12, HIGH TO 20
An equated token may not be used within the same source line as its definition. For example EQUATE NAME TO CLIENT.REC(1) ; NAME = "" will not recognise the use of NAME in the second statement as being a reference to CLIENT.REC(1)
If the equated name is also a built-in function or statement, that function or statement becomes inaccessible.
Examples
EQUATE ADDRESS TO 1 EQUATE TEL.NO TO 2 ... READ REC FROM DATA.FILE, ID THEN PRINT "Address: " : REC<ADDRESS> PRINT "Telephone: " : REC<TEL.NO> END
The above program fragment attaches name to two fields of a data record and then uses these when the data is extracted for printing.
EQUATE ADDRESS TO REC(1) EQUATE TEL.NO TO REC(2) DIM REC(10) ... MATREAD REC FROM DATA.FILE, ID THEN PRINT "Address: " : ADDRESS PRINT "Telephone: " : TEL.NO END
This program fragment achieves the same as the previous example but uses the MATREAD statement to separate the fields of the record read from the file into the elements of matrix REC. The names defined in the EQUATE statements are then used to reference elements of this matrix
EQUATE VALUE LIT "COST * QTY" COST = 14 QTY = 2 DISPLAY VALUE
The above example uses an equated token, VALUE, to represent the calculation of COST * QTY. When executed, this example would display the value 28.
See also: |