03-27-2024, 06:26 PM
My apologies Terence. I meant the code to be an addition to Steve's
Code: (Select All)
ReDim foo(0) As Long 'the array that's going to hold an uncertain amount of data
Randomize Timer
limit = Rnd * 1000000 + 1000000 'now, nobody knows how large this limit is going to be. Right?
'Let's run some tests with various ways to fill an array with this uncertain amount of data
t# = Timer(0.001)
count = 0
Do
foo(count) = count
If count < limit Then
count = count + 1
ReDim _Preserve foo(count)
Else
Exit Do
End If
Loop
t1# = Timer(0.001)
Print Using "There were ###,###,### items in the array, and it took us ##.### seconds to fill it."; UBound(foo), t1# - t#
'Now, let's clear all that data and try a different method
ReDim foo(10000000) As Long 'big enough to hold the data, no matter what
t# = Timer(0.001)
count = 0 'reset the counter
Do
foo(count) = count
If count < limit Then
count = count + 1
Else
Exit Do
End If
Loop
ReDim _Preserve foo(count)
t1# = Timer(0.001)
Print Using "There were ###,###,### items in the array, and it took us ##.### seconds to fill it."; UBound(foo), t1# - t#
t# = Timer(0.001)
count = 0
For c = 1 To limit: count = count + 1: Next
Dim Shared foo(count)
Print Using "There were ###,###,### items in the array, and it took us ##.### seconds to fill it."; UBound(foo), t1# - t#