4 Data Variables and Data handling
COM
DIM
INTEGER
DINTEGER
SHORT
REAL
They can be placed anywhere in a program. The size (number of dimensions and bounds of each dimension) of the array, which is specified, is known as the physical or maximum size. A new working size can be specified for the array, which cannot be greater than the total number of elements of the physical size. This can be done using a REDIM statement. The working size refers to the total number of elements being used. An array identifier, consisting of the array name and *, can be used to refer to all elements in the working size.
OPTION BASE 1
This statement must come before any of the variable declarative statements used in a program. Then any lower bound not specified is 1. (Explicitly defining a lower bound for an array always over-rules an OPTION BASE statement.)
If OPTION BASE 1 is not declared in a program, you may wish to include the statement:
OPTION BASE 0
for documentation purposes.
The OPTION BASE statement cannot be executed from the keyboard.
DIM item1 [,item2 . . . ]
DIM [instance : type_name]
DIM [instance AS type_name]
Each item can be one of the following:
10 OPTION BASE 1 20 DIM A(4,4),B$[56],C$(2,5),D$(10,10)[30],E(-5;5,-5;5)Line 20 dimensions array A to be of 16 elements maximum. (The elements are REAL numeric precision, the default.) B$ is dimensioned as a simple string of 56 characters maximum; C$ is a string array of ten 18-character strings maximum (the default maximum length for strings); D$ is a string array having one hundred 30-character strings; and E is a real numeric array of 100 elements.
The maximum number of characters that may be specified for a simple string (or string array element) is 32767. This size may be limited by the memory available.
Note that in a DIM statement the subscripts must be explicitly quoted; it is not possible to use the default maximum array or string size.
User Defined Type example:
DIM Vehicle AS Tvehicle DIM Vehicle:TvehicleThe type has to be defined before the variable can be dimensioned, see chapter , User defined Types.
The NEW statement makes it possible to dimension a variable during runtime of the program.
Syntax:
NEW instance : type_name
NEW instance AS type_name
It is possible to create a variable form an already existing one:
Syntax:
NEW STRUCT A = B
The variable A has the same type as the variable B, after executing this statement. The contant of variable B is not copied to A.
INTEGER numeric variable1 [(subscripts)] [,num variable2 [(subscripts)]. . .]
For example:
40 INTEGER X,Y(2,2)declares a simple integer X and an integer array Y.
declares a double integer variable. (see also INTEGER above.)
SHORT numeric variable1 [(subscripts)] [,num variable2 [(subscripts)]. . .]
For example:
50 SHORT A(4,5,6),B(3,2,1),Ddeclares A and B as short-precision arrays and D as a simple, short precision variable.
REAL numeric variable1 [(subscripts)] [,num variable2 [(subscripts)]. . .]
For example:
60 REAL M(2,3,4,5),Ndimensions the array M and simple variable N.
COM item1 [,item2 . . . ]
COM [instance : type_name]
COM [instance AS type_name]
Each item can be one of the following:
For example:
70 COM A,B(2,4),C$,#3,INTEGER E,F$(5)[24],G,SHORT H(5),I,DINTEGER D1,D2The variables A,B(2,4) and G are real precision. Real precision is assumed at the beginning of the COM list and for numeric variables declared after any string. All variables following a numeric precision keyword have that precision until another type is specified or a string is declared. Thus both H(5) and I are short precision. The #3 item allows passing an assigned data file of the same number to another program or subprogram. For example:
Main Program Overlay 10 COM A,B,#1 200 COM A,B,#5 20 ASSIGN #1 TO "Data" 30 CALL Data_prog . . 10 SUB Data prog Start of Subprogram 20 COM C,D,#3 . .The file number item in line 10 allows the file assigned in line 20 to remain assigned in the subprogram (as file #3) and in the overlayed program (as file #5). COM may occur anywhere in each program and may be edited.
The names of variables in corresponding COM statements need not match. But all items must be of the same type and be in the same order. Arrays must have the same number of dimensions and elements. Once a string is dimensioned in common, it is automatically dimensioned to the same size in all subsequent subprograms.
COM statements in separate programs need not have the same number of items. You need only quote the items that other programs or overlays need. A second (or further) COM statement in the main program will, if shorter, cause the omitted items to be lost or the extra files to be closed. If the succeeding COM list is longer, the new items will be dimensioned and initialized.
EXAMPLE OF TYPE USED AS GLOBAL VARIABLE
At pre-run initialization, all variables declared in DIM, SHORT, INTEGER, DINTEGER, and REAL are dimensioned and initialized. ("Initialization" means that numeric variables are set to 0 and string variables to the null string.)
DIM need not be used to assign space for strings with 18 character or less or for arrays having upper bounds of ten or
less. These can be dimensioned implicitly. (They will be set to the default--18 characters per string and 10 elements per dimension.)
A program can have more than one DIM, SHORT, INTEGER, DINTEGER or REAL statement, but the same variable name can be declared only once in a program segment. The same name, however, may be used for a simple numeric, simple string, numeric array and string array. For instance:
10 OPTION BASE 1 20 DIM A(5,5),A$[50],A$(10)[80]These variable names are legal, although confusing.