# EQUATE

Updated: 11/30/2021, 7:00:45 PM
Created: 11/30/2021, 7:00:45 PM
Last Updated By: Jake Tuttle
Read Time: 1 minute(s)

Tags: program variables

# Description

EQUATE is used to declare a symbol equivalent to a literal, variable or simple expression. It takes the general form:

EQU{ATE} symbol TO expression
1

where:

  • symbol is the name of the symbol to use;.can be any name that would be valid for a variable, and
  • expression can be a literal, a variable or a simple expression.

# Note

Sensible use of EQUATE symbols can make a program easier to maintain, read, and even more efficient.

Efficiency can be enhanced because the address of an EQUATEd value is computed during compilation and is substituted for each occurrence of the symbol name. Unlike the address of a variable, which must be computed for each access during run time, the address of a symbol is always known. This significantly reduces the processing overhead involved in accessing a particular value.

The snippet of code below illustrates how to enhance readability by referring to say, QTY rather than INV_LINE(4). Simply "EQUATE QTY TO INV_LINE(4)" at an early stage in the program. This can also help with maintenance of the program, particularly in situations where record layouts might change.

For example, if the quantity field moves to INV_LINE(6), you only have to change one line in the  program.

COMMON FLAG
EQUATE NO_CHARGE TO FLAG
EQUATE CR TO CHAR (13), TRUE TO 1, FALSE TO 0
EQUATE PRICE TO INV_LINE(7), TAX TO 0.175
EQUATE DASHES TO "-------"
IF NO_CHARGE = TRUE THEN PRICE = 0
CRT "Tax = " : PRICE * TAX : CR : DASHES
1
2
3
4
5
6
7

Go back to jBASE BASIC

Go back to Programmers' Reference Guide