magace Posted September 30, 2014 Share Posted September 30, 2014 I am working on a simple custom shutdown timer. I made it where when you press the start button the script reads how much time in hr/min you want to wait before it sleeps. Then I make it go into a while loop that stays on until the time has passed then it turns it off and shutdowns or what ever you choose in the combo box. My question is how would I go about exiting the while loop inside Case $idBtn with the stop button Case $isBtn? Here is my code and sorry if things are unclear just ask if you have any questions! expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Date.au3> CustomSleep() Func CustomSleep() Local $iWidthCell = 70 Local $hGUI = GUICreate("parent", 140, 120 -1, $WS_EX_ACCEPTFILES) ;creates parent gui to hide from taskbar $hGUI_No_TaskBar_1 = GUICreate("Sleep Timer", 120, 120, 100, 100, Default, Default, $hGUI); main gui WinSetTrans($hGUI_No_TaskBar_1, "", 170) ;make gui transparent GUICtrlCreateLabel("Sleep Timer", 25, 5) ;sleep timer laBEL GUICtrlCreateLabel("HR:", 1, 27) ;hr label Local $shr = GUICtrlCreateInput("0",20, 25, 20, 20);hr input box GUICtrlCreateLabel("MIN:", 45, 27) ;min label Local $smin = GUICtrlCreateInput("45", 70, 25, 20, 20) ;min input box GUICtrlSetState(-1, $GUI_DROPACCEPTED) Local $idBtn = GUICtrlCreateButton("Start", 1, 75, 60, 20) ;start button Local $isBtn = GUICtrlCreateButton("Stop", 60, 75, 60, 20) ;stop button I need help making it break the go 1 while. Local $idComboBox = GUICtrlCreateCombo("Shut down", 30, 50, 80, 20) ;combo select box shutdown, logoff, etc.. GUICtrlSetData($idComboBox, "Restart|Log off|Sleep", "Shut down") ;combo data GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $isBtn $go1 = 0 ;this needs to end the while loop in the Case $idBtn Case $idBtn $go1 = 1 Local $hTimer = TimerInit() Local $hrt = GUICtrlRead($shr) * 3600000 ;hrs in ms Local $mrt = GUICtrlRead($smin) * 60000 ;min in ms Local $rtime = $mrt + $hrt ;hr + min while $go1 = 1 ;while 1 I want to break when $isBtn is pushed Local $fDiff = TimerDiff($hTimer) Local $ctime = $rtime - $fDiff GUICtrlCreateLabel(_Convert($ctime), 5, 23) sleep(5000) if $fDiff > $rtime Then ;if current time is greater than total time hr + min in ms it reads the combo and does what I selected ToolTip("TIME TO TURN OFF",0,0) $go1 = 0 $sComboRead = GUICtrlRead($idComboBox) if $sComboRead = "Shut down" Then $go1 = 0 Shutdown(1) EndIf if $sComboRead = "Restart" Then $go1 = 0 Shutdown(2) EndIf if $sComboRead = "Log off" Then $go1 = 0 Shutdown(4) EndIf if $sComboRead = "Sleep" Then $go1 = 0 Shutdown(64) EndIf EndIf WEnd EndSwitch WEnd EndFunc Func _Convert($ms) Local $day, $hour, $min, $sec _TicksToTime($ms, $hour, $min, $sec) If $hour > 24 Then $day = $hour/24 $hour = Mod($hour, 24) EndIf Return StringFormat("%02iD/%02iH/%02iM/%02iS", $day, $hour, $min, $sec) EndFunc Link to comment Share on other sites More sharing options...
JohnOne Posted September 30, 2014 Share Posted September 30, 2014 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Date.au3> CustomSleep() Func CustomSleep() Local $iWidthCell = 70 Local $hGUI = GUICreate("parent", 140, 120 - 1, $WS_EX_ACCEPTFILES) ;creates parent gui to hide from taskbar $hGUI_No_TaskBar_1 = GUICreate("Sleep Timer", 120, 120, 100, 100, Default, Default, $hGUI); main gui WinSetTrans($hGUI_No_TaskBar_1, "", 170) ;make gui transparent GUICtrlCreateLabel("Sleep Timer", 25, 5) ;sleep timer laBEL GUICtrlCreateLabel("HR:", 1, 27) ;hr label Local $shr = GUICtrlCreateInput("0", 20, 25, 20, 20);hr input box GUICtrlCreateLabel("MIN:", 45, 27) ;min label Local $smin = GUICtrlCreateInput("45", 70, 25, 20, 20) ;min input box GUICtrlSetState(-1, $GUI_DROPACCEPTED) Local $idBtn = GUICtrlCreateButton("Start", 1, 75, 60, 20) ;start button Local $isBtn = GUICtrlCreateButton("Stop", 60, 75, 60, 20) ;stop button I need help making it break the go 1 while. Local $idComboBox = GUICtrlCreateCombo("Shut down", 30, 50, 80, 20) ;combo select box _MyFunc, logoff, etc.. GUICtrlSetData($idComboBox, "Restart|Log off|Sleep", "Shut down") ;combo data GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $isBtn $go1 = 0 ;this needs to end the while loop in the Case $idBtn Case $idBtn $go1 = 1 Local $hTimer = TimerInit() Local $hrt = GUICtrlRead($shr) * 3600000 ;hrs in ms Local $mrt = GUICtrlRead($smin) * 60000 ;min in ms Local $rtime = $mrt + $hrt ;hr + min While $go1 = 1 ;while 1 I want to break when $isBtn is pushed ConsoleWrite("In that while loop" & @LF);####################################### Local $fDiff = TimerDiff($hTimer) Local $ctime = $rtime - $fDiff GUICtrlCreateLabel(_Convert($ctime), 5, 23) ;############################################################################## ;Replace Sleep(5000) with a timer $timer = TimerInit() Do ;Poll for button. If GUIGetMsg() = $isBtn Then ExitLoop 2 EndIf Until TimerDiff($timer) >= 5000 ;############################################################################## If $fDiff > $rtime Then ;if current time is greater than total time hr + min in ms it reads the combo and does what I selected ToolTip("TIME TO TURN OFF", 0, 0) $go1 = 0 $sComboRead = GUICtrlRead($idComboBox) If $sComboRead = "Shut down" Then $go1 = 0 _MyFunc(1) EndIf If $sComboRead = "Restart" Then $go1 = 0 _MyFunc(2) EndIf If $sComboRead = "Log off" Then $go1 = 0 _MyFunc(4) EndIf If $sComboRead = "Sleep" Then $go1 = 0 _MyFunc(64) EndIf EndIf WEnd ConsoleWrite("Not in while loop" & @LF);####################################### EndSwitch WEnd EndFunc ;==>CustomSleep Func _Convert($ms) Local $day, $hour, $min, $sec _TicksToTime($ms, $hour, $min, $sec) If $hour > 24 Then $day = $hour / 24 $hour = Mod($hour, 24) EndIf Return StringFormat("%02iD/%02iH/%02iM/%02iS", $day, $hour, $min, $sec) EndFunc ;==>_Convert Func _MyFunc($val) For $i = 1 To $val Beep(700, 150) Next EndFunc ;==>_MyFunc AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. 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