Olhado_ Posted February 3, 2009 Posted February 3, 2009 So, I understand how to re-size an array and have even done it; but I have this case (attached), where I cannot seem to re-size the array. I basically have a dynamic array that I can re-size once, by removing the first item (zero item); but I then want to re-size this array again to get rid of the empty strings. However, I have tried every possible option I know of and I cannot seem to get it. I have even tried, just for kicks to stick actually numbers in there (as opposed to calculated values) and I still have no luck. The two methods I have tried is hard coding in the following: ReDim intFirstBlank As Integer I then tried to do a loop of a procedure, designed to remove items from arrays and what I used to re-size the array at the first time. Could someone take a look at it? I am especially confused at why I can re-size it once; but not again. Thanks, Chris Test.zip Quote
fixo Posted February 3, 2009 Posted February 3, 2009 Try to change the next part of code, e.g.: AdjustArray: Do While (UBound(MyArray) >= intFirstBlank) ArrayRemoveItem MyArray, UBound(MyArray) ReDim Preserve MyArray(0 To UBound(MyArray) - 1) Loop Not tested though ~'J'~ Quote
rocheey Posted February 4, 2009 Posted February 4, 2009 too much code to sift thru at the moment, but several places id start: 1) Dimming a dynamic array as a constant 2)passing a real array off to a sub as a safearray 3) using the undimmed "File" variable to step thru the results of the reduced array 4) seeding a list box with one huge string rather than adding individual items 5) dimming the array with an LBOUND of 0, but seeding the listbox with only item 1 of the array. Some quick code for removal of array items: '- snip-----------snip----------- Sub main() Dim maxarray As Long: maxarray = 5 ReDim MyArray(0 To maxarray) Debug.Print "Seeding array" For i% = LBound(MyArray) To UBound(MyArray) MyArray(i%) = String$(i% + 1, Chr$(65 + i%)) Debug.Print i%, MyArray(i%) Next i% For j% = 1 To 3 Debug.Print "Erasing first array item" ' erase item 0 For i% = LBound(MyArray) To UBound(MyArray) - 1 MyArray(i%) = MyArray(i% + 1) Debug.Print i%, MyArray(i%) Next i% maxarray = maxarray - 1 ReDim Preserve MyArray(0 To maxarray) Next j% End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.