Jmatta
Jmatta

Reputation: 11

Do Until Loop. One or another condition is met

I am trying to create a loop to have Excel tell a DOS based system to search for a condition. If it doesn't find the condition I get stuck in an infinite loop. I have found many situations where a loop will go until it meets a condition. But is there a way to have it run until the condition is met OR an integer reaches a point? I am VERY new to VBA, so take my lack of knowledge lightly please.

I have tried several of the single condition guides, and purchased VBA for dummies, (not a great deal of help)

Sub Test ()
    DOS.readscreen StrLoop 3, 1, 4  

    Do Until StrLoop = "TXT"

    Loop
End Sub

I'm hoping to have an integer count to a certain point and if it reaches a point have it exit the loop. I am just uncertain of how to do it.

Upvotes: 1

Views: 546

Answers (2)

Ronan Vico
Ronan Vico

Reputation: 605

You need to change the variable strloop , until get to a value

dim i as long 
Do Until StrLoop = "TXT" or i = 1000
      DOS.readscreen StrLoop 3, 1, 4  
      i = i + 1 
Loop

Upvotes: 2

GSerg
GSerg

Reputation: 78175

Dim StrLoop as string, i as long

Do
    DOS.readscreen StrLoop 3, 1, 4
    i = i + 1
Loop Until StrLoop = "TXT" or i = 1000

Upvotes: 3

Related Questions