Defining variables
Quick reference
To define a data variable, type:
data name size[s]
To define an integer variable, type:
int name size[s]
To define a real variable, type:
real name size[s]
Type s after the variable’s size if you want to be able to omit the parentheses from references to single cells in the variable.
Before Quantum will recognize named variables in your program, you must say what type of information the variable is to contain and how many cells it should have. To increase the size of the C array, you must indicate how many cells you require.
You can declare named variables in these places:
▪In the variables file. Variables declared here are available in the edit and tab sections of your program and also in subroutines, and may be changed by the edit or by a subroutine.
▪At the start of your program before the ed statement. Variables declared here are available in the edit and tab sections of your program and also in subroutines and may be changed by the edit or by a subroutine.
▪In the edit after the ed statement. Variables declared here are available in the edit section only and may only be changed there. They are unknown to the tab section and to subroutines.
All variable definitions are made up of three items, separated by spaces:
▪the type:
data for data variables
int for integer variables
real for real variables
▪the name: C, T or X to increase the number of data, integer or real variables available; any name for a new variable.
▪the size. This is generally the number of cells the variable is to have.
Here are some examples:
data c 1500
increases the size of the C array to 1500 cells. This provides space for records with up to 14 cards per respondent.
int number_of_trips 5
creates an integer variable called number_of_trips which can store up to five whole numbers.
real price 10
creates a real variable with room to store ten real numbers.
Note Increasing the C array with a
data,
int or
real statement does not cause Quantum to clear the extra cells between records. However, when you increase the C array by using the
max= option on the
struct statement, Quantum automatically clears the entire array between records. For more information on
max=, see
Highest card type number.
The individual cells of an array may be referenced by following the name of the array by the cell number enclosed in parentheses. Therefore:
meals(3) | means the third cell of the variable meals |
c(100) | is the 100th cell of the C array |
You can omit the parentheses when you are referring to a single cell in the C array so that c100 means the same as c(100). To make this possible, you must follow the variable size with the letter ‘s’. This is particularly important when you are increasing the size of the C array as, without it, any references to, say, c15 will cause errors. For example, if you write:
data c 1200s
you are increasing the size of the C array to 1200 cells — enough for 11 cards per record. Because the array size is followed by ‘s’ you can write c1056 when you mean c(1056): Quantum will substitute the parentheses automatically.
The dimension of the C array will be taken automatically from the value of max= on the struct statement if this is greater than the dimension requested in the variables file or at the start of your program file.
For example, if you have:
int c 1300s
in your variables file or at the start of your program file, and:
struct;max=15;ser=c(1,4);crd=c(79,80); ....
in your program, the C array will be increased to 1600 cells to accommodate card type 15.
Do not confuse a declaration of the form:
int brand 1s
with a similar one which omits the ‘s’:
int brand 1
The former creates the variable ‘brand’ as an array, and you can refer to it in your program as brand1. The latter creates a single named variable that must be referred to as brand.
See also