Huh? MatchArr starts off with a Ubound of 0 (first redim). In the while loop, top is set to the current Ubound, then the array is redimmed to one greater than top. That gets you to 1 on the first loop. Next time around, top is set to 1 and the array is redimmed at 2 (1+1). Option Base has nothing to do with it, and is generally a bad idea unless you use it everywhere and make sure that you add it to the comments of every sub and function you create as well as to the Options area – it counts as “unexpected behaviour”. Personally, I’d use a List rather than an array if I know it’s going to have to redimmed a thousand and twenty-three times; it’s a lot less expensive than continual redim preserves.
In my case I, indeed, need to fill the array with almost 20000 entries. Is it the wise to use a list instead an array? If I use redim for each entry does that affect the performance a lot? I have seen that the filling of my arra takes more than 40 minutes. And thats a lot for the server on which it should run.
Yes, it would affect performance. Every Redim Preserve essentially creates a whole new copy of the array in a new memory location, with one extra element allotted. Using a list would be a lot faster:
Dim MatchList List As String
top = 0
while not doc is nothing
IncNo = result.GetValue(1)
MonthN = Cint(result.GetValue(3))
YearN = Cint(result.GetValue(4))
MatchArr(Cstr(top)) = Cstr(ticketmatchCount)
top = top + 1
numRows = numRows + 1
Wend
In the end, you are left with a list having list tags like “0”, “1”, “2”, etc. If you still need an array, you can dump the list into one:
(Assume “Dim MatchArray() As String” is still decalred earlier)
Redim MatchArray(top - 1)
Forall entry In MatchList
MatchArray(Cint(ListTag(entry)) = entry
End Forall
That should go a heck of a lot faster than the method you’re using now.