EQUATE

EQUATE, EQU

Top  Previous  Next

 

The EQUATE statement, often abbreviated to EQU, defines a symbolic name to represent a QMBasic expression.

 

 

Format

 

EQUATE name LITERALLY "string"

EQUATE name TO expression

 

where

nameis the name to be attached to the value or matrix reference.
stringis a quoted string consisting of QMBasic language elements.
expressionis any valid QMBasic expression.

 

 

The EQUATE statement defines a name that can be used later within the program as a reference to the string or expression.

 

In most cases, the two forms of this statement are interchangeable but the first form will be needed if the string contains unpaired brackets. The LITERALLY keyword may be abbreviated to LIT.

 

The second for of the EQUATE statement can alternatively be written using the $DEFINE compiler directive.

 

EQUATE statements are often placed in include records so that the same values can be incorporated into many programs without duplication. Common uses of EQUATE include:

 

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:

$DEFINE, GENERATE