Purpose
Re-sizes an array variable.
Syntax
ReDim var_name ( newsize ) [ , ... ]
var_name is a string representing the name of an existing local or global array variable.
newsize is an integer value dictating the new array size. The maximum value is 32,767.
Description
The ReDim statement re-sizes (or "re-dimensions") one or more existing array variables. The variable identified by var_name must have already been defined as an array variable through a Dim statement or a Global statement.
The ReDim statement can increase or decrease the size of an existing array. If your program no longer needs a given array variable, the ReDim statement can re-size that array to have zero elements (this minimizes the amount of memory required to store variables).
Unlike some BASIC languages, MapBasic does not allow custom subscript settings for arrays; a MapBasic array's first element always has a subscript of one.
If you store values in an array, and then enlarge the array through the ReDim statement, the values you stored in the array remain intact.
Example
Dim names_list(10) As String, cur_size As Integer
' The following statements determine the current
' size of the array, and then ReDim the array to
' a size 10 elements larger
cur_size = UBound(names_list)
ReDim names_list(cur_size + 10)
' The following statement ReDims the array to a
' size of zero elements. Presumably, this array
' is no longer needed, and it is resized to zero
' for the sake of saving memory.
ReDim names_list(0)
As shown below, the ReDim statement can operate on arrays of custom Type variables, and also on arrays that are Type elements.
Type customer
name As String
serial_nums(0) As Integer
End Type
Dim new_customers(1) As customer
' First, redimension the "new_customers" array,
' making it five items deep:
ReDim new_customers(5)
' Now, redimension the "serial_nums" array element
' of the first item in the "new_customers" array:
ReDim new_customers(1).serial_nums(10)
See Also:
Dim statement, Global statement, UBound() function