4 Data Variables and Data handling

Redimensioning an Array

A new working size for an array can be established by using the statement.

REDIM array variable1 (redim subscripts)[,array variable2 (redim subscripts)...]

The REDIM subscripts have features and properties identical to normal array subscripts. Any array, once redimensioned, will behave as if it was originally defined with the new dimensions. That is, accessing an element beyond the new range will return ERROR 17. Data in variables beyond the new range cannot now be accessed.

REDIM cannot be used to release memory space for other uses. An array redimensioned as smaller will occupy the same amount of memory; it will just act as if smaller. When using REDIM, remember that the number of dimensions cannot change and the total number of elements may not exceed the number originally dimensioned (meaning, the maximum physical size may not be increased).


10  OPTION BASE 0
20  DIM A(100),B(20,20),Astring$(25)[50],Bstring$(25,25)
30  ! Various arrays dimensioned as examples.
40  REDIM A(50)  ! Change array A from A(0:100) to A(0:50).
50  !
60  REDIM A(100:199) ! Now alter A from A(0:50) to A(100:199).
70  !
80  REDIM B(10,15)  ! Change B(0:20,0:20) to B(0:10,0:15).
90  !
100REDIM B(1:21,1:21) !Restore B to original size with new lower bound.
110 !
120 REDIM A(80),B(5,35) ! Change both arrays at once.
130 !
140 REDIM B(40)!Incorrect number of dimensions may not be altered.
150 !
160 REDIM A(120) ! Incorrect original number of elements exceeded.
170 !
180 REDIM Astring$(10) ! Change Astring$ from (0:25)[50] to (0:10)[50].
190 !
200 REDIM Bstring$(5,100) ! Change Bstring$ from (0:25,0:25)[18].
210 !to (0:5,0:100)[18] The default string length does not change.
220 !Bstring had 26*26 = 676 elements, now has 6*101=606 elements.
240 END

Eloquence Language Manual - 19 DEC 2002