Archived

This topic is now archived and is closed to further replies.

ju2wheels

VB -- dynamic 2d array

Recommended Posts

I want to create a 2d array that I can resize at runtime but am having trouble creating it... for example i want to be able to say Dim strArray(2,unkown ) as String and later be able to do this Redim strArray(0, new_value) Redim strArray(1, new_value)

Share this post


Link to post
Share on other sites
You can only resize the last dimension of an array.

So you could do...

Dim blah(1) As String
Redim blah(1,2) As String

Or

Dim blah(1, 1) As String
Redim blah(1, 4) As String

But not

Dim blah(1) as String
ReDim blah(2, 10) As String

Might be worth explicitly specifying lower and upper bounds like...

Dim blah(1 to 10, 1 to 5) As String
Dim blah(0 to 4, 0 to 9, 0 to 49) As String

Or using the Option Base directive (at module level) to specify the lower bound.

By default...
Dim blah(9) As String would give (0 to 9)

Whereas Option Base 1
Dim blah(9) As String would give (1 to 9)

Hope this hasn''t confused you!

Cheers,
Paul Cunningham

PS - (use optional Preserve Keyword to save the existing data in the array when resizing)

Share this post


Link to post
Share on other sites