vba: a forever loop

Posted by I__ on Stack Overflow See other posts from Stack Overflow or by I__
Published on 2010-06-10T21:26:44Z Indexed on 2010/06/10 22:02 UTC
Read the original article Hit count: 234

Filed under:
|
|
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?

© Stack Overflow or respective owner

Related posts about excel

Related posts about vba