Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private myArray() As argType
Private Type argType
a As Long
b As String
c As Integer
d As Currency
exists As Boolean
End Type
Private Function jamie() As Long
Dim tempTime As Long, elapsed As Long, n As Long, i As Long
Dim tempArr() As argType
For n = 0 To 9
tempTime = GetTickCount
ReDim myArray(99999)
For i = 0 To 99999
myArray(i).exists = Not ((i Mod 100) = 0)
Next
ReDim tempArr(0)
For i = 0 To UBound(myArray)
If myArray(i).exists Then
tempArr(UBound(tempArr)) = myArray(i)
ReDim Preserve tempArr(UBound(tempArr) + 1)
End If
Next
ReDim pyarray(UBound(tempArr))
myArray = tempArr
tempTime = GetTickCount - tempTime
elapsed = elapsed + tempTime
Next
jamie = (elapsed / 10)
End Function
Private Function stuart() As Long
Dim tempTime As Long, elapsed As Long, n As Long, i As Long
Dim tempArr() As argType, lCounter As Long
For n = 0 To 9
tempTime = GetTickCount
ReDim myArray(99999)
For i = 0 To 99999
myArray(i).exists = Not ((i Mod 100) = 0)
Next
lCounter = -1
ReDim tempArr(UBound(myArray))
For i = 0 To UBound(myArray)
If myArray(i).exists Then
lCounter = lCounter + 1
tempArr(lCounter) = myArray(i)
End If
Next
ReDim Preserve tempArr(lCounter)
ReDim myArray(lCounter)
myArray = tempArr
tempTime = GetTickCount - tempTime
elapsed = elapsed + tempTime
Next
stuart = (elapsed / 10)
End Function
Private Sub Form_Load()
MsgBox "Times taken : " & vbCrLf & vbCrLf & _
"Jamie's Method : " & jamie & vbCrLf & _
"Stuart's Method : " & stuart, vbInformation
End Sub