Declaring an array with empty parentheses (without dimension subscripts) is called Dynamic arrays.
Ex: Public\Private\Dim ArrayName ( )
The Dim Statement is used to declare the Size for Static array.
The ReDim statement is used to size or resize a dynamic array.
Using ReDim statement You can change the number of elements and dimensions in an array repeatedly.
Using ReDim statement You can change the number of elements and dimensions in an array repeatedly.
Ex: 1 ) Dim X(10)
ReDim X(15)
Ex :2 ). Dim X(10, 10)
ReDim X(10, 15)
Here if your array has two or more dimensions, you can change the size of only the last dimension only.
NOTE: If you are using ReDim for changing the size or Dimensions of Dynamic array, it's erasing an existing data contained in the array. to avoid this you should use Preserve Keyword before the array name.
Ex: Dim X(10)
ReDim Preserve X(15)
.
ReplyDelete