Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    Blue Springs, Missouri, USA
    Posts
    108
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Breaking out of a Loop (XL2K3 SP1)

    I have written this deliberate loop. It is a countdown timer. I am looking for a way to break out of it preferably by a user pressing a button. The code...

    Sub StartTimer()
    Do
    Calculate
    newHr = Hour(Now())
    newMin = Minute(Now())
    newSec = Second(Now()) + 1
    waitTime = TimeSerial(newHr, newMin, newSec)
    Application.Wait waitTime
    Loop
    End Sub

    I don't want to press Ctrl+Break or any other key combinations. Do I have to change the update time? Can this even be done?

    Thanx for any help / insight.

    Dennis

    <img src=/S/gramps.gif border=0 alt=gramps width=20 height=20>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Breaking out of a Loop (XL2K3 SP1)

    You can define a global variable blnStop of type Boolean:

    Public blnStop As Boolean

    Modify the StartTimer procedure:

    Sub StartTimer()
    blnStop = False
    Do While blnStop = False
    Calculate
    newHr = Hour(Now())
    newMin = Minute(Now())
    newSec = Second(Now()) + 1
    waitTime = TimeSerial(newHr, newMin, newSec)
    Application.Wait waitTime
    Loop
    End Sub

    The code behind your button must set blnStop = True.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •