Jump to content

Timer


 Share

Recommended Posts

This is just an small all purpose, down counter, in the left field you enter the hours an in the right the minutes and the progressbar will show you the status till the programmed time is over.

#include <GUIConstants.au3>
GUICreate("Clock", 210, 100)
$OK_Btn = GUICtrlCreateButton("Start", 10, 10, 70, 25)
$std = GUICtrlCreateInput ("Hours", 90,  10, 50, 25)
$min = GUICtrlCreateInput ("Min", 150,  10, 50, 25)
GuiCtrlCreateLabel(":", 142, 14, 5, 25)
$lab = GUICtrlCreateLabel("Time left: ", 10, 50, 200, 20)
$progressbar1 = GUICtrlCreateProgress (10,70,190,20)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    
    Select
        
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
         
        Case $msg = $OK_Btn
            if GUICtrlRead($OK_Btn) = "Start" Then
                $time = (StringIsDigit(GUICtrlRead($std)) Or StringIsFloat(GUICtrlRead($std)))* GUICtrlRead($std) * 3600
                $time += (StringIsDigit(GUICtrlRead($min)) Or StringIsFloat(GUICtrlRead($min))) * GUICtrlRead($min) * 60    
                GUICtrlSetData ($OK_Btn,"Stop")
                $begin = TimerInit()
                While Int(TimerDiff($begin)/1000) <= $time
                    $Diffhour = Int($time/3600 - TimerDiff($begin)/3600000)
                    $Diffmin = Int(Mod($time/60 - TimerDiff($begin)/60000, 60))
                    $Diffsek = Int(Mod($time - TimerDiff($begin)/1000, 60))
                    GUICtrlSetData($lab, "Time Left: " & $Diffhour & " h " & $DiffMin & " min " & $Diffsek & " sec ")
                    GUICtrlSetData($progressbar1, (Int(TimerDiff($begin)/1000)/$time)*100)
                    if Int(TimerDiff($begin)/1000) = $time then
                        GUICtrlSetData($progressbar1, 100) 
                        SoundPlay(@WindowsDir & "\Media\Tada.wav", 1)
                        GUICtrlSetData($progressbar1, 0)
                        GUICtrlSetData ($OK_Btn,"Start")
                        ContinueCase 
                    EndIf
                    if GUIGetMsg() = $OK_Btn then 
                        GUICtrlSetData($progressbar1, 0)
                        GUICtrlSetData ($OK_Btn,"Start")
                        ContinueCase 
                    EndIf
                    Sleep(10)
                WEnd
            ElseIf GUICtrlRead($OK_Btn) = "Stop" Then
                GUICtrlSetData ($OK_Btn,"Start")
            EndIf
            
        Case @error
         
    EndSelect
     
 WEnd

If you have any suggestion please tell me. For example, for some reason I had to add this "Case @error" as some kind as dummy case so that the "Continue Case" finds another case to proceed. In a previous version I diddn't need this to work, if you know why or have any other ideas just say, I'm eager to learn new tricks ;P In any other case just enjoy the programm if you find use for it.

Edited by CHronologist
Link to comment
Share on other sites

Thanks for the reply. You are right a visible countdown would be more practical, but I decided against it, because this is not intended to be a stopwatch, but a timer that reminds you of something you have to do after a certain time while you do other things. So the program normally runs in background and for this purpose a visible countdown would have meant more work than needed and the progressbar looks more nice^^ You are free to add this function, I would be interested in seeing how you do it.

Edited by CHronologist
Link to comment
Share on other sites

Nice!! Here is my input on your cool countdown timer... muttley

#include <GUIConstants.au3>

GUICreate("Quick Timer", 210, 115)
$OK_Btn = GUICtrlCreateButton("Start", 10, 25, 70, 25)
$std = GUICtrlCreateInput ( "", 90,  25, 50, 25)
$hidde = GUICtrlCreateInput("", 150, 25, 50, 25)

GuiCtrlCreateLabel("Hours", 90, 10, 50, 15)
GuiCtrlCreateLabel("Minutes", 150, 10, 70, 15)


GuiCtrlCreateLabel(":", 142, 29, 5, 25)
$progressbar1 = GUICtrlCreateProgress (10,85,190,20)
$Minutes = GUICtrlCreateCombo("Minutes  0", 110, 55, 80, 25) ;added zero to keep from erroring out.
GUICtrlSetData(-1, "1 Minutes|3 Minutes|5 Minutes|10 Minutes|15 Minutes|20 Minutes|25 Minutes|30 Minutes|45 Minutes|50 Minutes|59 Minutes")
$Hours = GUICtrlCreateCombo("Hours  0", 10, 55, 65, 25) ;added zero to keep from erroring out.
GUICtrlSetData(-1, "1 Hour|2 Hours|3 Hours|4 Hours|5 Hours|6 Hours|7 Hours|8 Hours|9 Hours")

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    
    Select
        
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
         
        Case $msg = $OK_Btn
            if GUICtrlRead($OK_Btn) = "Start" Then
    $asminuteResult = StringRegExp(GUICtrlRead($Minutes), '([\+-]*\d+\.*\d*)', 1) 
    GUICtrlSetData ($hidde, $asminuteResult[0])
    
    $ashourResult = StringRegExp(GUICtrlRead($Hours), '([\+-]*\d+\.*\d*)', 1) 
    GUICtrlSetData ($std, $ashourResult[0])
    
                $time = GUICtrlRead($std)*3600+GUICtrlRead($hidde)*60    
                GUICtrlSetData ($OK_Btn,"Stop")
                $begin = TimerInit()
                While Int(TimerDiff($begin)/1000) <= $time
                    GUICtrlSetData($progressbar1, (Int(TimerDiff($begin)/1000)/$time)*100)
                    if Int(TimerDiff($begin)/1000) = $time then
                        GUICtrlSetData($progressbar1, 100) 
                        SoundPlay(@WindowsDir & "\Media\Tada.wav", 1)
                        GUICtrlSetData($progressbar1, 0)
                        GUICtrlSetData ($OK_Btn,"Start")
                        ContinueCase 
                    EndIf
                    if GUIGetMsg() = $OK_Btn then 
                        GUICtrlSetData($progressbar1, 0)
                        GUICtrlSetData ($OK_Btn,"Start")
                        ContinueCase 
                    EndIf
                WEnd
            ElseIf GUICtrlRead($OK_Btn) = "Stop" Then
                GUICtrlSetData ($OK_Btn,"Start")
            EndIf
            
        Case @error
         
    EndSelect
     
WEnd
Link to comment
Share on other sites

nice done @gesller, makes it better to handle without losing the compact style I wanted to produce. Thanks

The only problem you might solve is, that now the programm doesn't seem to accept entries from the input field.

Edited by CHronologist
Link to comment
Share on other sites

Ok, Here it is.. I fixed the trouble above with not letting you add numbers into the inputs and added your function with the visible countdown.

#include <GUIConstants.au3>

GUICreate("Quick Timer", 210, 130)
$OK_Btn = GUICtrlCreateButton("Start", 10, 10, 70, 25)
$std = GUICtrlCreateInput ( "", 90,  25, 50, 25)
$hidde = GUICtrlCreateInput("", 150, 25, 50, 25)

GuiCtrlCreateLabel("Hours", 90, 10, 50, 15)
GuiCtrlCreateLabel("Minutes", 150, 10, 70, 15)


GuiCtrlCreateLabel(":", 142, 29, 5, 25)
$progressbar1 = GUICtrlCreateProgress (10,105,190,20)
$lab = GUICtrlCreateLabel("Time left: ", 10, 90, 200, 15)

$Clear = GUICtrlCreateButton("clear", 10, 35, 70, 25)

$Minutes = GUICtrlCreateCombo("Minutes", 110, 65, 85, 25) ;added zero to keep from erroring out.
GUICtrlSetData(-1, "1 Minutes|3 Minutes|5 Minutes|10 Minutes|15 Minutes|20 Minutes|25 Minutes|30 Minutes|45 Minutes|50 Minutes|59 Minutes")


$Hours = GUICtrlCreateCombo("Hours", 10, 65, 85, 25) ;added zero to keep from erroring out.
GUICtrlSetData(-1, "1 Hour|2 Hours|3 Hours|4 Hours|5 Hours|6 Hours|7 Hours|8 Hours|9 Hours")

    
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    
    Select
 Case $msg = $Hours
   $ashourResult = StringRegExp(GUICtrlRead($Hours), '([\+-]*\d+\.*\d*)', 1) 
   GUICtrlSetData ($std, $ashourResult[0])
  Case $msg = $Minutes
   $asminuteResult = StringRegExp(GUICtrlRead($Minutes), '([\+-]*\d+\.*\d*)', 1) 
   GUICtrlSetData ($hidde, $asminuteResult[0])
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
         Case $msg = $Clear
    _Clear_All()
        Case $msg = $OK_Btn
            if GUICtrlRead($OK_Btn) = "Start" Then
                $time = (StringIsDigit(GUICtrlRead($std)) Or StringIsFloat(GUICtrlRead($std)))* GUICtrlRead($std) * 3600
                $time += (StringIsDigit(GUICtrlRead($hidde)) Or StringIsFloat(GUICtrlRead($hidde))) * GUICtrlRead($hidde) * 60    
                GUICtrlSetData ($OK_Btn,"Stop")
                $begin = TimerInit()
                While Int(TimerDiff($begin)/1000) <= $time
                    $Diffhour = Int($time/3600 - TimerDiff($begin)/3600000)
                    $Diffmin = Int(Mod($time/60 - TimerDiff($begin)/60000, 60))
                    $Diffsek = Int(Mod($time - TimerDiff($begin)/1000, 60))
                    GUICtrlSetData($lab, "Time Left: " & $Diffhour & " h " & $DiffMin & " min " & $Diffsek & " sec ")
                    GUICtrlSetData($progressbar1, (Int(TimerDiff($begin)/1000)/$time)*100)
                    if Int(TimerDiff($begin)/1000) = $time then
                        GUICtrlSetData($progressbar1, 100) 
                        SoundPlay(@WindowsDir & "\Media\Tada.wav", 1)
                        GUICtrlSetData($progressbar1, 0)
                        GUICtrlSetData ($OK_Btn,"Start")
                        ContinueCase 
                    EndIf
                    if GUIGetMsg() = $OK_Btn then 
                        GUICtrlSetData($progressbar1, 0)
                        GUICtrlSetData ($OK_Btn,"Start")
                        ContinueCase 
                    EndIf
                    Sleep(10)
                WEnd
            ElseIf GUICtrlRead($OK_Btn) = "Stop" Then
                GUICtrlSetData ($OK_Btn,"Start")
            EndIf
            
        Case @error
         
    EndSelect
     
 WEnd
 
 Func _Clear_All()
GUICtrlSetData ($Hours, "Hours")
GUICtrlSetData ($Minutes, "Minutes")
GUICtrlSetData ($std, "")
GUICtrlSetData ($hidde, "")
EndFunc

Link to comment
Share on other sites

  • 6 months later...

*bows* thansk for positive feedback, trying to improve my scripting skill every day.

How about helping a newbie :-D

PLS can you make a simple version that I can implement as a function in my own scrip /GAME BOT/ That would show only time passed since starting specific function in the script.

I need a simple MSG/WINDOW/TRAY Status perhaps where I can see the progress. Thanks :-)

Link to comment
Share on other sites

Ok, Here it is.. I fixed the trouble above with not letting you add numbers into the inputs and added your function with the visible countdown.

#include <GUIConstants.au3>

GUICreate("Quick Timer", 210, 130)
$OK_Btn = GUICtrlCreateButton("Start", 10, 10, 70, 25)
$std = GUICtrlCreateInput ( "", 90,  25, 50, 25)
$hidde = GUICtrlCreateInput("", 150, 25, 50, 25)

GuiCtrlCreateLabel("Hours", 90, 10, 50, 15)
GuiCtrlCreateLabel("Minutes", 150, 10, 70, 15)


GuiCtrlCreateLabel(":", 142, 29, 5, 25)
$progressbar1 = GUICtrlCreateProgress (10,105,190,20)
$lab = GUICtrlCreateLabel("Time left: ", 10, 90, 200, 15)

$Clear = GUICtrlCreateButton("clear", 10, 35, 70, 25)

$Minutes = GUICtrlCreateCombo("Minutes", 110, 65, 85, 25) ;added zero to keep from erroring out.
GUICtrlSetData(-1, "1 Minutes|3 Minutes|5 Minutes|10 Minutes|15 Minutes|20 Minutes|25 Minutes|30 Minutes|45 Minutes|50 Minutes|59 Minutes")


$Hours = GUICtrlCreateCombo("Hours", 10, 65, 85, 25) ;added zero to keep from erroring out.
GUICtrlSetData(-1, "1 Hour|2 Hours|3 Hours|4 Hours|5 Hours|6 Hours|7 Hours|8 Hours|9 Hours")

    
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    
    Select
 Case $msg = $Hours
   $ashourResult = StringRegExp(GUICtrlRead($Hours), '([\+-]*\d+\.*\d*)', 1) 
   GUICtrlSetData ($std, $ashourResult[0])
  Case $msg = $Minutes
   $asminuteResult = StringRegExp(GUICtrlRead($Minutes), '([\+-]*\d+\.*\d*)', 1) 
   GUICtrlSetData ($hidde, $asminuteResult[0])
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
         Case $msg = $Clear
    _Clear_All()
        Case $msg = $OK_Btn
            if GUICtrlRead($OK_Btn) = "Start" Then
                $time = (StringIsDigit(GUICtrlRead($std)) Or StringIsFloat(GUICtrlRead($std)))* GUICtrlRead($std) * 3600
                $time += (StringIsDigit(GUICtrlRead($hidde)) Or StringIsFloat(GUICtrlRead($hidde))) * GUICtrlRead($hidde) * 60    
                GUICtrlSetData ($OK_Btn,"Stop")
                $begin = TimerInit()
                While Int(TimerDiff($begin)/1000) <= $time
                    $Diffhour = Int($time/3600 - TimerDiff($begin)/3600000)
                    $Diffmin = Int(Mod($time/60 - TimerDiff($begin)/60000, 60))
                    $Diffsek = Int(Mod($time - TimerDiff($begin)/1000, 60))
                    GUICtrlSetData($lab, "Time Left: " & $Diffhour & " h " & $DiffMin & " min " & $Diffsek & " sec ")
                    GUICtrlSetData($progressbar1, (Int(TimerDiff($begin)/1000)/$time)*100)
                    if Int(TimerDiff($begin)/1000) = $time then
                        GUICtrlSetData($progressbar1, 100) 
                        SoundPlay(@WindowsDir & "\Media\Tada.wav", 1)
                        GUICtrlSetData($progressbar1, 0)
                        GUICtrlSetData ($OK_Btn,"Start")
                        ContinueCase 
                    EndIf
                    if GUIGetMsg() = $OK_Btn then 
                        GUICtrlSetData($progressbar1, 0)
                        GUICtrlSetData ($OK_Btn,"Start")
                        ContinueCase 
                    EndIf
                    Sleep(10)
                WEnd
            ElseIf GUICtrlRead($OK_Btn) = "Stop" Then
                GUICtrlSetData ($OK_Btn,"Start")
            EndIf
            
        Case @error
         
    EndSelect
     
 WEnd
 
 Func _Clear_All()
GUICtrlSetData ($Hours, "Hours")
GUICtrlSetData ($Minutes, "Minutes")
GUICtrlSetData ($std, "")
GUICtrlSetData ($hidde, "")
EndFunc
thx gesller it's a AutoIt great script

Guys can anyone tell me what need to change to make...

- when i press OK_Btn the timer will start and i don't finish untill i press Stop btn.

constantly the time that I chose from Combo.

thx for help!

Edited by Muaddib
Link to comment
Share on other sites

thx gesller it's a AutoIt great script

Guys can anyone tell me what need to change to make...

- when i press OK_Btn the timer will start and i don't finish untill i press Stop btn.

constantly the time that I chose from Combo.

thx for help!

anyone?

Link to comment
Share on other sites

  • 4 months later...

Along with adding the previously-mentioned pause button, could you please add checking to see if the "Time Left" text actually changed before updating it.

Currently the label flashes - besides, if the text didn't change, it's unnecessary to set it again.

Eg:

You could create a variable to hold the Last value and a variable to hold the New;

Set the New value to the "Time Left" desired string, compare it with the Last, if it differs, update the GUI with the New value and set the Last equal to the current New value.

Rinse, wash, repeat.

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

  • 2 weeks later...

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...