|
Declaration statement that changes the space allocated
to an array that has already been declared by DIM, preserving as
much of the data as possible. Unlike other forms of BASIC this
handles memory in contiguous sections. Thus, REDIM might
overwrite existing variables in memory if you REDIM a small memory
block to a large memory block. Also it does not clean up after each
REDIM statement so memory usage keeps growing with each REDIM
statement.
Syntax: REDIM variable[(subscripts)] AS type DIM
B(20) AS INTEGER REDIM B(100) AS
INTEGER
Details: If the array has not yet been
declared by DIM, REDIM will be equivalent to calling DIM (except
when dealing with components, in which case you'll receive a
compiler error). You cannot change the data type for the array, ie.
you cannot redefine array B to be something other than an INTEGER
(as in the above example). Combining arrays is a by-product of
REDIM.DIM A(1 to 100) AS INTEGER
DIM B(1 to 100) AS INTEGER
REDIM A(1 to 200) AS INTEGER '-- Combines A and B together What
the above code does is preserve the data in A as well as combining
the array B.so index from 101 to 200 is the data for B and 1 to 100
is the data for A. Clarification: Array Bhas not been modified, it
still maintains its own address space and will notoverwrite A's data
and vice versa. Note that this by-product does not apply to
redimming Fixed Strings, Variants and Components.

DIM Button(1 TO 2, 1 TO 2) AS QBUTTON
REDIM Button(1 TO 2, 1 TO 4) AS QBUTTON Note that when
dealing with multiple dimensions the elements are shifted to fill
each column. So element (2,2) is actually moved to position (1,4).
Some problems to be aware of:
DIM A(1) AS STRING
REDIM A(20) AS STRING 'this redim works fine!
DIM A(1) AS STRING*4
REDIM A(20) AS STRING*4 'this redim causes an error! |