Dynamic Arrays...Redim Preserve

I am having troubles with dynamic arrays and need some help figuring out how to resize the array in certain situations.

I have a two-element array where it's first or second element may increase.  For example, Array(X, Y).
Now if Y increases, I do a Redim Preserve Array(X, Y), and it works fine.  However, if X increases, but Y does not, and then I do the Redim, I get a subscript out of range.  

Any tips on how resize dynamic arrays in different ways?  Thanks!
--Vingamel
LVL 1
VingamelAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
You can only redim the last dimension of your array.

Here is a copy-and-paste from the VB help:
"If you use the Preserve keyword, you can resize only the last array dimension and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array. The following example shows how you can increase the size of the last dimension of a dynamic array without erasing any existing data contained in the array."
0
 
VingamelAuthor Commented:
Thanks, that helps a lot.
0
 
VingamelAuthor Commented:
Thanks, that helps a lot.
0
 
VingamelAuthor Commented:
<The following example shows how you can increase the size of the last dimension of a dynamic array without erasing any existing data contained in the array.">

> There was no following example...
0
 
Éric MoreauSenior .Net ConsultantCommented:
Exactly as you do. For example:
Y = Y + 1
Redim Preserve Array(X, Y)
0
All Courses

From novice to tech pro — start learning today.