Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I interrupt a loop with a button click?

Status
Not open for further replies.

InkyRich

Technical User
Aug 2, 2006
126
GB
Hi,
Am I able to interrupt a loop with a click from a button?
Basically I have a basic alarm which I want to stop running from a button.
Any idea how I do this?

Inky

A fool and his money are soon parted - so you might as well send it to me!
 
Code:
[COLOR=black cyan]' In General Declarations[/color]
Dim StopTheLoop As Boolean

[COLOR=black cyan]' In Button_Click[/color]
Sub Button_Click()
   StopTheLoop = TRUE
End Sub

[COLOR=black cyan]' In the Loop[/color]
   Do While SomeCondition
      DoEvents
      If StopTheLoop Then
         StopTheLoop = FALSE
         Exit Do
      End If
      [COLOR=black cyan]' Loop Processing[/color]
   Loop
 
Thanks Golom,
You set me on the right track. I had to modify bits to get it to work but thanks for your input.

Inky

A fool and his money are soon parted - so you might as well send it to me!
 
Personally, I would control the execution of the alarm with a timer rather than a loop.

 
How are ya InkyRich . . .

Agree with [blue]JoeAtWork![/blue] A loop such as this is near [blue]processor intensive![/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top