Similarly, when you use
Preserve, you can change the size of the array only by changing the upper bound; changing the lower bound causes an error. If you make an array smaller than it was, data in the eliminated elements will be lost. If you pass an array to a procedure by reference, you can't redimension the array within the procedure. When variables are initialized, a numeric variable is initialized to 0, a variable-length string is initialized to a zero-length string (""), and a fixed-length string is filled with zeros.
Variant variables are initialized to
Empty. Each element of a user-defined type variable is initialized as if it were a separate variable. A variable that refers to an object must be assigned an existing object using the
Set statement before it can be used. Until it is assigned an object, the declared
object variable has the special value
Nothing, which indicates that it doesn't refer to any particular instance of an object. The
ReDim statement acts as a declarative statement if the variable it declares doesn't exist at
module level or
procedure level. If another variable with the same name is created later, even in a wider
scope,
ReDim will refer to the later variable and won't necessarily cause a compilation error, even if
Option Explicit is in effect. To avoid such conflicts,
ReDim should not be used as a declarative statement, but simply for redimensioning arrays.
Note To resize an array contained in a
Variant, you must explicitly declare the
Variant variable before attempting to resize its array.