Skip to main content
GameDev.net gamedev.net
🔒 Locked

VB -- dynamic 2d array

Started by ju2wheels Sep 1, 2003 at 10:39 PM 0 replies 850+ views
Original Post
ju2wheels
ju2wheels
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)
PaulCunningham
PaulCunningham
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)
Cheers,Paul CunninghamPumpkin Games

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.