Moderators Melba23 Posted March 15, 2009 Moderators Share Posted March 15, 2009 FSoft,Here you go. Use _TimeToTicks to get a tick value for your alarm time and then compare that value to the instantaneous _TimeToTicks value.As an added bonus, I have given you inputs that are limited to 2 characters, move automatically to the next when full, and have some errorchecking for the values entered by the user. No extra charge!expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <Date.au3> GUICreate("Timer Test", 200, 200) $label2 = GUICtrlCreateLabel("",20,20,100,20) GUICtrlSetState(-1, $GUI_HIDE) $button = GUICtrlCreateButton("Start", 20, 100, 80, 30) $hour = GUICtrlCreateInput("",20,150,20,20) GUICtrlSetLimit(-1, 2) $min = GUICtrlCreateInput("",50,150,20,20) GUICtrlSetLimit(-1, 2) $sec = GUICtrlCreateInput("",80,150,20,20) GUICtrlSetLimit(-1, 2) GUISetState() GUIRegisterMsg($WM_COMMAND, "On_WM_COMMAND") $fTimer = False Global $EndTicks = 0 $begin = TimerInit() While 1 Select Case TimerDiff($begin) > 1000 GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC) $begin = TimerInit() Case _TimeToTicks(@HOUR,@MIN,@SEC) = $EndTicks GUICtrlSetData($button, "Start") GUICtrlSetState($label2, $GUI_HIDE) For $i = $hour To $sec GUICtrlSetData($i, "") Next MsgBox(0, "Timer test", "Ding!") EndSelect Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $button $fTimer = Not $fTimer If $fTimer Then GUICtrlSetData($button, "Stop") GUICtrlSetState($label2, $GUI_SHOW) Set_Alarm() Else GUICtrlSetData($button, "Start") GUICtrlSetState($label2, $GUI_HIDE) EndIf EndSwitch WEnd Func Set_Alarm() $Alarm_Hour = GUICtrlRead($hour) If $Alarm_Hour > 23 Or $Alarm_Hour = "" Then $Alarm_Hour = 0 GUICtrlSetData($hour, "00") EndIf $Alarm_Min = GUICtrlRead($min) If $Alarm_Min > 59 Or $Alarm_Min = "" Then $Alarm_Min = 0 GUICtrlSetData($min, "00") EndIf $Alarm_Sec = GUICtrlRead($sec) If $Alarm_Sec > 59 Or $Alarm_Sec = "" Then $Alarm_Sec = 0 GUICtrlSetData($sec, "00") EndIf $EndTicks = _TimeToTicks($Alarm_Hour, $Alarm_Min, $Alarm_Sec) EndFunc Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam) $nNotifyCode = BitShift($wParam, 16) $nID = BitAnd($wParam, 0x0000FFFF) Switch $nNotifyCode Case 0x400;$EN_UPDATE If StringLen(GUICtrlRead($nID)) = 2 Then GUICtrlSetState($nID+1, $GUI_FOCUS) EndSwitch EndFuncM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Floppy Posted March 15, 2009 Author Share Posted March 15, 2009 FSoft, Here you go. Use _TimeToTicks to get a tick value for your alarm time and then compare that value to the instantaneous _TimeToTicks value. As an added bonus, I have given you inputs that are limited to 2 characters, move automatically to the next when full, and have some errorchecking for the values entered by the user. No extra charge!expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <Date.au3> GUICreate("Timer Test", 200, 200) $label2 = GUICtrlCreateLabel("",20,20,100,20) GUICtrlSetState(-1, $GUI_HIDE) $button = GUICtrlCreateButton("Start", 20, 100, 80, 30) $hour = GUICtrlCreateInput("",20,150,20,20) GUICtrlSetLimit(-1, 2) $min = GUICtrlCreateInput("",50,150,20,20) GUICtrlSetLimit(-1, 2) $sec = GUICtrlCreateInput("",80,150,20,20) GUICtrlSetLimit(-1, 2) GUISetState() GUIRegisterMsg($WM_COMMAND, "On_WM_COMMAND") $fTimer = False Global $EndTicks = 0 $begin = TimerInit() While 1 Select Case TimerDiff($begin) > 1000 GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC) $begin = TimerInit() Case _TimeToTicks(@HOUR,@MIN,@SEC) = $EndTicks GUICtrlSetData($button, "Start") GUICtrlSetState($label2, $GUI_HIDE) For $i = $hour To $sec GUICtrlSetData($i, "") Next MsgBox(0, "Timer test", "Ding!") EndSelect Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $button $fTimer = Not $fTimer If $fTimer Then GUICtrlSetData($button, "Stop") GUICtrlSetState($label2, $GUI_SHOW) Set_Alarm() Else GUICtrlSetData($button, "Start") GUICtrlSetState($label2, $GUI_HIDE) EndIf EndSwitch WEnd Func Set_Alarm() $Alarm_Hour = GUICtrlRead($hour) If $Alarm_Hour > 23 Or $Alarm_Hour = "" Then $Alarm_Hour = 0 GUICtrlSetData($hour, "00") EndIf $Alarm_Min = GUICtrlRead($min) If $Alarm_Min > 59 Or $Alarm_Min = "" Then $Alarm_Min = 0 GUICtrlSetData($min, "00") EndIf $Alarm_Sec = GUICtrlRead($sec) If $Alarm_Sec > 59 Or $Alarm_Sec = "" Then $Alarm_Sec = 0 GUICtrlSetData($sec, "00") EndIf $EndTicks = _TimeToTicks($Alarm_Hour, $Alarm_Min, $Alarm_Sec) EndFunc Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam) $nNotifyCode = BitShift($wParam, 16) $nID = BitAnd($wParam, 0x0000FFFF) Switch $nNotifyCode Case 0x400;$EN_UPDATE If StringLen(GUICtrlRead($nID)) = 2 Then GUICtrlSetState($nID+1, $GUI_FOCUS) EndSwitch EndFunc M23 Thanks a lot! Link to comment Share on other sites More sharing options...
Floppy Posted March 15, 2009 Author Share Posted March 15, 2009 Another thing: I don't want to hide the clock when i click Stop. I want to set it to "00:00:00". I tried with GuiCtrlSetData, but without results. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 15, 2009 Moderators Share Posted March 15, 2009 FSoft,It took me about 10 seconds to see how to do this. If you want to become a competent AutoIt coder, you have got to learn how to do simple things like this yourself. However......Add a label which only reads "00:00:00" - then hide it with the timer when it is displayed. And because I am feeling really magnanimous, here is the new line to add:$label1 = GUICtrlCreateLabel("00:00:00",20,20,100,20)But you have to work out where it goes. ;-)M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Floppy Posted March 16, 2009 Author Share Posted March 16, 2009 FSoft, It took me about 10 seconds to see how to do this. If you want to become a competent AutoIt coder, you have got to learn how to do simple things like this yourself. However...... Add a label which only reads "00:00:00" - then hide it with the timer when it is displayed. And because I am feeling really magnanimous, here is the new line to add:$label1 = GUICtrlCreateLabel("00:00:00",20,20,100,20) But you have to work out where it goes. ;-) M23 Thank you very much AutoIt is a simple scripting language and you can do many many things with a few strings; but, on the other hand, sometimes, it's difficult. [This is only my opinion, I don't want to say that AutoIt sucks.. ] Bye Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now