1.

What is ReDim statement?

Answer»

The ReDim statement is used to resize or enlarge a dynamic array that has already been formally declared with empty parenthesis using a PRIVATE, Public, or Dim declaration (without dimension subscripts). To alter the NUMBER of elements and dimensions in an array, use the ReDim statement repeatedly. However, unless the array is included in a Variant, one can't define an array of one DATA type and then use ReDim to transform it to another data type. If the array is stored in a Variant, the type of the items can be changed with an As type clause, unless the Preserve keyword is used, in which case no data type changes are allowed.

An example of the usage of the ReDim keyword is given below:

Dim DemoArray() As Integer ' Declaring a dynamic array. Redim DemoArray(10) ' Allocating 10 elements. For J = 1 To 10 ' Looping for 10 times. DemoArray(J) = J ' Initializing the DemoArray. Next J

The ReDim statement is used in the above example to allocate and reallocate storage space for dynamic array variables in this example. The Option Base is assumed to be 1. The ReDim keyword is only applicable to arrays and is used to modify the size of one or more dimensions of an array that has already been declared. When NEEDED, Redim can FREE up or add elements to an array.



Discussion

No Comment Found