• Countdown Timer

    • This topic has 2 replies, 2 voices, and was last updated 24 years ago.
    Author
    Topic
    #356512

    Trying to make a countdown timer and have written the following code:

    Dim intCounter As Integer
    intCounter = 60
    Do While intCounter > 0
    Me!lblCountdown.Caption = intCounter
    intCounter = intCounter – 1
    Loop

    Timer Interval for the form is set to 1000

    There will also be code to display “Time Up” or similar.

    My problem is that it immediately displays 1, suggesting that the code is not looping once per second, however the looping is working if i step through the code (intCounter reduces by one each loop)

    Where am i going wrong???

    Thanks

    Viewing 0 reply threads
    Author
    Replies
    • #527809

      Hi Peter,
      What you need to do is something like the following (you’ve probably already done some of this):
      1. Add a textbox (e.g. txtTimer) to hold the timer value
      2. Add code to the form Load event to set the inital value:
      – e.g. Me!txtTimer = 60
      3. Set TimerInterval to required value (in your case 1000)
      4. Add code to the OnTimer event of the form to decrease the textbox value by 1 and check if it has reached zero – e.g.
      Private Sub Form_Timer()
      With Me
      !txtTimer = !txtTimer – 1
      If !txtTimer = 0 Then
      MsgBox “Time up!”
      .TimerInterval = 0
      End If
      End With
      End Sub
      Hope that helps.

      • #527813

        Rory. That’s great thank you. I can see now that my code was running in it’s entirety on the timer event, and not one loop at a time. Great!

    Viewing 0 reply threads
    Reply To: Countdown Timer

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

    Your information: