Jump to content

Countdown Timer


Recommended Posts

Hi all,

I'm looking for a countdown timer that counts down to zero and starting from a time specified script. I found this code in one of the topics about this:

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 122, 42, 438, 156)
$Label1 = GUICtrlCreateLabel("1:00", 8, 8, 43, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$time=TimerInit()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch

$new = TimerDiff ($time)
$new = (1*60*1000)-$new
$seconds = Round ($new/1000)
$newMin = Floor ($seconds/60)
$newSec = Mod ($seconds, 60)
If $newSec < 10 Then $newSec = "0"&$newSec
GUICtrlSetData ($Label1, $newMin&":"&$newSec)
WEnd

But that code doesn't stop at 0:00 . Is there a way to stop it when the countdown is 0:00?

thanks!

Edited by PcExpert
Link to comment
Share on other sites

You have a long way to go. :)

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 122, 42, 438, 156)
$Label1 = GUICtrlCreateLabel("1:00", 8, 8, 43, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


$time = TimerInit()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    $new = (1 * 60 * 1000) - TimerDiff($time)
    $seconds = Round($new / 1000)
    $newMin = Floor($seconds / 60)
    $newSec = Mod($seconds, 60)
    If $newSec < 10 Then $newSec = "0" & $newSec
    If ($newMin > 0 Or Number($newSec) > 0) Then 
        GUICtrlSetData($Label1, $newMin & ":" & $newSec)
    Else
        GUICtrlSetData($Label1, "0:00")
    EndIf
WEnd
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...