Redim 2D Array with larger capacity

wildfire1982

Regular
Joined
Oct 23, 2003
Messages
50
Location
Southampton
I have a 2d Array and i need to increase the first dimension. Is this possible? I cant seem to get it to do it. I dont really want to have to change all of the code but if there isnt another way... i suppose i will have to.


Ta very much.

Chris
 
Would switching your dimensional order work?
i.e.
(dimension1, dimension2) -> (dimension2, dimension1)?

Other than that, the following works in VB6 and I'd assume that it works in .NET.
Code:
Public Structure MyArray
  Public Elements() As Integer
End Structure
Public DualResizeArray() As Integer
And then, you can resize each dynamic array with Redim.
:)
 
Depends on if you're trying to preserve your data, in which case "redim preserve" won't do the trick. Otherwise, you'll have to make a new array and copy the original array members into the new array, which "preserve" is doing behind the scenes anyhow (creating a new array).

Here's from MSDN:
ReDim releases the existing array and creates a new array with the same rank. The elements of the new array are initialized to the default value for their data type unless you specify Preserve.

If you include the Preserve keyword, Visual Basic copies the elements from the existing array to the new array. When you use Preserve, you can resize only the last dimension of the array, and for every other dimension you must specify the same size it already has in the existing array.

For example, if your array has only one dimension, you can resize that dimension and still preserve the contents of the array, 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 if you use Preserve.
 
Back
Top