Numeric Constants, Variables, and Arrays
Constants
A numeric constant is a sequence of digits and special characters representing some numeric value. There are times when PRO/5 must convert text into some internal format representing a numerical value. A program line may contain numeric constants. For example:
1000 LET X=3.14
The program may try to convert a sequence of characters to a numeric value using the NUM() function. For example:
1000 LET X=NUM("3.14")
The program may request input of a number from the keyboard or a file. For example:
1000 INPUT X
In each of these cases PRO/5 will recognize any sequence of characters conforming to the following rules:
-
Leading and trailing spaces are ignored. A number may not contain embedded spaces. (Exceptions may be made after using SETOPTS. See SETOPTS for more information.)
-
A number must begin with either a +, -, . or a digit.
-
A number may have any number of digits. Any digits beyond the maximum precision are rounded and discarded.
-
An exponent may be given by following the number with an "E" or "e", an optional sign ("+" or "-"), and any number of digits.
-
Overflow and underflow may occur. An overflow generates an error. An underflow becomes zero.
-
A null string or a string of all spaces is valid and becomes zero.
Variables
-
A numeric variable is represented by a single letter (A..Z) optionally followed by up to 31 letters, digits, and underscores (_).Some examples are X, VAL2, and TEST1A.
-
The name of a variable cannot begin with "FN".
-
The length of a variable name has no effect on execution speed and minimal effect on program size.
-
During program execution, any numeric variable that has not been explicitly assigned a value will default to zero. Note that this behavior can be modified using SETOPTS.
Arrays
PRO/5 supports numeric arrays with as many as three dimensions. The programmer may specify the lower and upper bounds of subscripts in each dimension. In PRO/5, arrays are completely dynamic. The DIM verb is used to allocate and reallocate arrays. Unlike some BASICs, the mere presence of a DIM verb in a program is not enough. In PRO/5, a DIM verb must actually be executed before an array may be accessed.
Array names are subject to the same rules as simple numeric variables. However, brackets must immediately follow the array name; for example, A0[1]. To ease porting of older Business BASIC programs, PRO/5 will recognize parentheses as well as brackets. However, PRO/5 will internally convert the parentheses to brackets. If there is some ambiguity with a numeric function, for example ABS(X) and ABS[X], brackets must be used if an array is intended. PRO/5 will not confuse array names with the names of simple numeric variables. The numeric variable A0 and the numeric array A0[] may both exist without conflict.
PRO/5 arrays are row major. The DIM verb specifies the number of dimensions and range of subscript values for each dimension. When accessing an array element, an error is issued if you do not use the proper number of subscripts, or if any of the subscripts is outside the dimension range.
Examples
1000 DIM A[10,3]
1010 LET X=A[5,0]
2000 DIM B[-5:20,100]
2010 PRINT B[-3,50]