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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.