Sfx Posted May 22, 2010 Share Posted May 22, 2010 I need help putting in a function that would be able to count up to X amount of minutes when I click the GUI Reset time button; My current code for the GUI is below. Thanks in advance. expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $ExitID Global $time _Main() Func _Main() Local $YesID GUICreate("timer", 350, 80) GUICtrlCreateLabel($time, 10, 10) $YesID = GUICtrlCreateButton("Restart Timer", 10, 50, 200, 20) GUICtrlSetOnEvent($YesID, "reset") $ExitID = GUICtrlCreateButton("Exit", 300, 50, 50, 20) GUICtrlSetOnEvent($ExitID, "OnExit") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() ; display the GUI While 1 Sleep(1000) WEnd EndFunc ;==>_Main ;--------------- Functions --------------- Func Reset() MsgBox(0, "Timer Reset to Zero", "Ok") $time = 0 EndFunc ;==>OnYes Func OnExit() If @GUI_CtrlId = $ExitID Then EndIf Exit EndFunc ;==>OnExit Link to comment Share on other sites More sharing options...
Yoriz Posted May 22, 2010 Share Posted May 22, 2010 Not sure if this is what you want , but it should help you along the way. expandcollapse popup#include <GUIConstantsEx.au3> #include <Date.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $ExitID Global $iX = 2, $iStartTime, $stime, $hTimeLabel _Main() Func _Main() Local $YesID GUICreate("timer", 350, 80) $hTimeLabel = GUICtrlCreateLabel("", 10, 10, 100, 20) $YesID = GUICtrlCreateButton("Restart Timer", 10, 50, 200, 20) GUICtrlSetOnEvent($YesID, "reset") $ExitID = GUICtrlCreateButton("Exit", 300, 50, 50, 20) GUICtrlSetOnEvent($ExitID, "OnExit") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() ; display the GUI $iStartTime = TimerInit() While 1 _UpdateTimmer() Sleep(1000) WEnd EndFunc ;==>_Main ;--------------- Functions --------------- Func Reset() MsgBox(0, "Timer Reset to Zero", "Ok") $iStartTime = TimerInit() EndFunc ;==>Reset Func OnExit() If @GUI_CtrlId = $ExitID Then EndIf Exit EndFunc ;==>OnExit Func _UpdateTimmer() Local $iHours, $iMins, $iSecs, $sNewtime, $iTimeDif $iTimeDif = TimerDiff($iStartTime) _TicksToTime($iTimeDif, $iHours, $iMins, $iSecs) $sNewtime = StringFormat("%02s", $iHours) & ":" & StringFormat("%02s", $iMins) & ":" & StringFormat("%02s", $iSecs) If $stime <> $sNewtime Then $stime = $sNewtime GUICtrlSetData($hTimeLabel, $stime) EndIf If $iMins = $iX Then MsgBox(0, "", "Reached " & $iX & " Minutes") Exit EndIf EndFunc ;==>_UpdateTimmer GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
Sfx Posted May 22, 2010 Author Share Posted May 22, 2010 Not sure if this is what you want , but it should help you along the way. expandcollapse popup#include <GUIConstantsEx.au3> #include <Date.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $ExitID Global $iX = 2, $iStartTime, $stime, $hTimeLabel _Main() Func _Main() Local $YesID GUICreate("timer", 350, 80) $hTimeLabel = GUICtrlCreateLabel("", 10, 10, 100, 20) $YesID = GUICtrlCreateButton("Restart Timer", 10, 50, 200, 20) GUICtrlSetOnEvent($YesID, "reset") $ExitID = GUICtrlCreateButton("Exit", 300, 50, 50, 20) GUICtrlSetOnEvent($ExitID, "OnExit") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() ; display the GUI $iStartTime = TimerInit() While 1 _UpdateTimmer() Sleep(1000) WEnd EndFunc ;==>_Main ;--------------- Functions --------------- Func Reset() MsgBox(0, "Timer Reset to Zero", "Ok") $iStartTime = TimerInit() EndFunc ;==>Reset Func OnExit() If @GUI_CtrlId = $ExitID Then EndIf Exit EndFunc ;==>OnExit Func _UpdateTimmer() Local $iHours, $iMins, $iSecs, $sNewtime, $iTimeDif $iTimeDif = TimerDiff($iStartTime) _TicksToTime($iTimeDif, $iHours, $iMins, $iSecs) $sNewtime = StringFormat("%02s", $iHours) & ":" & StringFormat("%02s", $iMins) & ":" & StringFormat("%02s", $iSecs) If $stime <> $sNewtime Then $stime = $sNewtime GUICtrlSetData($hTimeLabel, $stime) EndIf If $iMins = $iX Then MsgBox(0, "", "Reached " & $iX & " Minutes") Exit EndIf EndFunc ;==>_UpdateTimmer Thank you, this helped quite a bit, How would I go about making a msgbox Pop up when the Timer reaches X time? Link to comment Share on other sites More sharing options...
Yoriz Posted May 22, 2010 Share Posted May 22, 2010 Thank you, this helped quite a bit, How would I go about making a msgbox Pop up when the Timer reaches X time?X time is set to 2 minutes in my example, if you was to let it run for 2 minutes you will find it already does this when it reaches x minutes. GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. 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