DIM (numeric array)
Dimension Numeric Array
This directive defines a numeric array of up to three dimensions.
Syntax
Section titled “Syntax”DIM array-name(dim1 [, dim2 [, dim3]]) [, array-name (dim1 [, dim2 [,dim3]])...]array-name- is any numeric variable name.
dim1,2,3- is an index specifying the number of entries in the first, second, and third dimensions of the array as described below.
Remarks
Section titled “Remarks”Starting with release level 8.1B2, a lower boundary other than zero can be specified for each index.
The syntax for index values dim1,2,3 is:
[low-index:] high-indexlow-index- is a signed integer that specifies the lower bound of each range. This option is generally available starting with release level 8.1B2. Prior release levels do not have this option and use a lower bound of zero (0).
high-index- is a signed integer specifying the higher bound of each range.
If the low index is not specified, then the default for starting the array element is 0.
The low index and the high index can be negative integers provided that the range does not exceed 65000 entries.
If the low index has a greater value than the high index, an ERR=41 results.
65000 is the maximum number of total entries in the numeric array and 64999 is the
maximum number of any individual dimension.
The statement, which dimensions a numeric array, must be executed before any reference can be made to that numeric array.
Each element of the array is initialized to 0 when the array is dimensioned, but can contain any valid number within the limits of Thoroughbred Basic.
Memory space used to store an array may be released by redimensioning the array to 0.
If dim1 is 5, dim2 is 10, and dim3 is 15, this array has 6 occurrences in the first dimension, 11 in the second, and 16 in the third for a total of 1056 entries.
More than one variable can be dimensioned in a statement by separating the variable names with commas.
Starting with release level 8.0, the parentheses in the syntax print as brackets ( “[” and “]” ) and may be entered as brackets. This shows the DIM directives for both numeric and string arrays with brackets while the DIM Function and DIM directive for a simple string shows parentheses when LISTed. To avoid LISTing brackets in release levels starting with 8.0 use the PRM LISTPAREN parameter in the IPLINPUT file (see the chapter on System Files in the Thoroughbred Basic Customization and Tuning Guide). With PRM LISTPAREN, the DIM directives list as in releases prior to 8.0.
If you use the CALL directive to call a public program that will permanently change the value of an array element, you must pass the entire array to the called program. Array elements are passed by value, so any changes to the element will not be reflected in the calling program. For more information and examples, please refer to the description of the CALL directive.
Examples
Section titled “Examples”DIM A(X)If X=5, defines an array with the 6 elements: A(0), A(1), A(2), A(3), A(4), A(5).
DIM A(X:Y)If X=3 and Y=8, this statement defines an array with 6 elements: A(3), A(4), A(5), A(6), A(7), A(8).
DIM B(2,3)defines a two-dimensional array with the elements:
B (0,0) B (1,0) B (2,0)
B (0,1) B (1,1) B (2,1)
B (0,2) B (1,2) B (2,2)
B (0,3) B (1,3) B (2,3)
DIM B(0)releases memory space set up in the example above and eliminates the numeric array.
DIM A(X), ARRAY_NAME(5)If X=5, this statement sets up the same numeric array as the first example and another numeric array of the same size named ARRAY_NAME.
DIM THREE_DIM_ARRAY(2,2,2)defines a three-dimensional array having a total of 27 elements.
DIM A(2:8,3,-4:6)defines a three-dimensional array. The first dimension has 7 elements with 2 as the lowest index. The second dimension has 4 elements with 0 as the lowest index (default). The third dimension has 11 elements, with -4 as the lowest index.
See also
Section titled “See also”DIM string and DIM string array directives
DIM and NEA functions
From the Thoroughbred Basic Language Reference, Volume I: A–E, version 8.9.1. Open this page in the PDF