• Breaking out of a Loop (XL2K3 SP1)

    • This topic has 1 reply, 2 voices, and was last updated 20 years ago.
    Author
    Topic
    #419921

    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

    gramps

    Viewing 0 reply threads
    Author
    Replies
    • #949477

      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.

    Viewing 0 reply threads
    Reply To: Breaking out of a Loop (XL2K3 SP1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: