Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redim MultiDimensional Array Problem 1

Status
Not open for further replies.

Becca999

Programmer
Oct 14, 2003
23
US
Hi, If anyone can help!!

I have a global array where I set the bounds once the user makes a selection. The user has choices that would cause the array to grow but because you cannot redim Preserve the lower bounds of a multidimensional array, I thought I save what was there is a temp array, erase & redim the global array one larger then reset the global array to the temp array and add the new chioce. It does not error on the code but it doesn't ever increase the UBound of the first element:

In Module:
Global AnArray()
Global intArryCntr as Integer

Once UserMakesSelection:
gintArryCntr = NumberOfVersions
ReDim AnArray(1 To gintArryCntr, cNumOfElements)
'** Populate each element of array with each version

If User added a Version:
Sub ResetArray()

Dim intNewBounds As Integer
Dim aTemp() As Variant

intNewBounds = gintArryCntr + 1
ReDim aTemp(1 To intNewBounds, cNumOfElements)
aTemp = AnArray
Erase AnArray
gintArryCntr = intNewBounds
ReDim AnArray(1 To gintArryCntr, cNumOfElements)
AnArray = aTemp
Erase aTemp

End Sub

Sub PopulateNewVersion(ArrayIndex as integer)

'** Code to populate the new version
AnArray(ArrayIndex, 1) = (whatever) -> FAILS HERE w. Script out of range. I did a Print UBound and it was the same as the first ReDim.

End Sub


Any ideas or alternative solutions?
Thanks!

 
You will have to copy the individual elements of the temporary array to the new array. When you define a variable as an array you are actually defining a pointer to the array so when you move one variable containing an array to another variable containig an array, you only move a pointer. The same thing happens with strings. Moving a smaller string to a larger string just moves a pointer such that you get the smaller string, not a copy of the smaller string inside the larger string.

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
A different thought? It appears that you are only ever changing one dimension? (the first of hte two)? If so, just swap the 'order' of the elements within the array and you can use ReDim Preserve and just re-organize the display.



MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top