Let me apologize up front for a very basic question, but after reading the documentation and several posts on the forum, I’m not sure I understand how this works.
The documentation says…
The Redim command can be used to increase or decrease the number of elements in a previously declared array. Unlike with Dim, the various upper bound values can be Integer literals, constants, variables or expressions.
I think I’m good with this. Redim changes the dimensions of an array you’ve already dimentioned
When you Redim an array to an unbounded size (using -1 as the upperBound), then all its elements are removed. It is faster to use Redim in this manner to clear any array rather than looping through the array and calling the Remove method on each element.
Redim(-1) alone removes all elements of the array? I’ve read elsewhere on the forum that it only makes the array “unbounded” and the data, if any, from the previous dimensioned use is retained until you Redim(positiveValue). So, which clears all the values, redim anArray(-1), or Redim anArray(-1) then Redim anArray(X)?
Second question. What is the meaning of an unbounded array? Does this mean that after Redim anArray(-1) , anArray(N) = X is valid for all N, assuming memory allows? If this is true, is there a performance penalty for using unbounded arrays?
When you increase the size of an array, any existing values are retained.
Is this true for enlarging any dimension of the array? For example, Dim anArray(10,20,30) followed by Redim anArray(11,22,31) retains all data from the previous dimensioning? What data, if any, resides in the newly dimensioned space?
When you decrease the size of an array, existing values are retained if they are still within the new array bounds.
Same question as increasing dimension size. Does this retain the data when reducing the size of any dimension in a multidimensional array?
Sorry again for this very basic question (ok, questions plural), but the more I researched, the more confused I became, and by not understanding this, I envision hours of pain trying to figure out why things work sometimes and not others and fighting the dreaded “out of bounds” error.
Thanks,
Gary