vba: a forever loop
- by I__
Sub something(tecan)
On Error Resume Next
Dim arr As New Collection, a
Dim aFirstArray() As Variant
Dim i As Long
aFirstArray() = Array(Dir(tecan & "*.ESY", vbNormal))
aFirstArray(0) = Mid(aFirstArray(0), 1, 4)
Do While Dir <> ""
ReDim Preserve aFirstArray(UBound(aFirstArray) + 1)
aFirstArray(UBound(aFirstArray)) = Mid(Dir, 1, 4)
Loop
On Error Resume Next
For Each a In aFirstArray
arr.Add a, a
Next
For i = 1 To arr.Count
Cells(i, 1) = arr(i)
'open_esy (tecan & arr(i) & "*")
Next
Erase aFirstArray
For i = 1 To arr.Count
arr.Remove i
Next i
here is how i call this sub:
something (tecan1)
something (tecan2)
on the first call it works and does what it is supposed to
but on the second call it gets stuck in this loop:
Do While Dir <> ""
ReDim Preserve aFirstArray(UBound(aFirstArray) + 1)
aFirstArray(UBound(aFirstArray)) = Mid(Dir, 1, 4)
Loop
why does it get stuck in the loop?