ptt Posted June 19, 2007 Share Posted June 19, 2007 Hi guys, I make a stop watch .... for examp i set it 20 secconds to count down to 0 then will alarm me ..but how can i stop the loop whenever i can while it is still looping? I tried ctrl break from keyboard but it wont stop the loop..it keep going all to the end then exit instead. I was reading on guisetonevent , i did that way but it doesnt do anything either. Any master can offer me some help i woujld be very appreciated. here is my function alarm func alarm($ala) ; i start with ala = 20 for example. for $i = 1 to $ala sleep(1000) GUICtrlSetData($secl,$i ) ; i set the label to display the counting down number Next SoundPlay(@WindowsDir & "\media\ringout.WAV",1) EndFunc here is my whole code with gui #include <GUIConstants.au3> global $ala1, $ala2, $stopv #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("AC", 234, 187, 442, 247) GUISetFont (30, 9000, Default) $hrl = GUICtrlCreateLabel("00:", 8, 24, 70, 100) GUISetFont (30, 9000, Default) GUICtrlSetColor (-1, 0xFF0000) $minl = GUICtrlCreateLabel("00:", 72, 24, 70, 100) GUISetFont (30, 9000, Default) GUICtrlSetColor (-1, 0xFF0000) $secl = GUICtrlCreateLabel("00", 136, 24, 43, 100) GUISetFont (30, 9000, Default) GUICtrlSetColor (-1, 0xFF0000) GUISetFont (10, Default, Default) $alarm1 = GUICtrlCreateButton("Alarm1", 8, 145, 75, 25, 0) $alarm2 = GUICtrlCreateButton("Alarm2", 100, 145, 75, 25, 0) ;$stop = GUICtrlCreateButton("Stop", 180, 145, 50, 25, 0) $set20 = GUICtrlCreateButton("SetAlarm1", 150, 90, 75, 25) ;$set2 = GUICtrlCreateButton("SetAlarm2", 150, 121, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $ala1 = 20 $ala2 = 10 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $set20 $temp = InputBox(""," Enter #secs for alarm ") if asc($temp) > 47 and asc($temp) < 58 then $ala1 = $temp Elseif $temp <> "" then msgbox(1,"","Pls enter a number") EndIf case $alarm1 alarm($ala1) case $alarm2 alarm($ala2) EndSwitch WEnd func alarm($ala) ; i start with ala = 20 for example. for $i = 1 to $ala sleep(1000) GUICtrlSetData($secl,$i ) ; i set the label to display the counting down number Next SoundPlay(@WindowsDir & "\media\ringout.WAV",1) EndFunc Link to comment Share on other sites More sharing options...
MisterBates Posted June 19, 2007 Share Posted June 19, 2007 Hi guys, I make a stop watch .... for examp i set it 20 secconds to count down to 0 then will alarm me ..but how can i stop the loop whenever i can while it is still looping?I tried ctrl break from keyboard but it wont stop the loop..it keep going all to the end then exit instead. I was reading on guisetonevent , i did that way but it doesnt do anything either. Any master can offer me some help i woujld be very appreciated.One way to do this would be to bind a function to a hotkey, so that when the hotkey is pressed, the function can set a global variable ($bCancelled?) to TRUE. Set this variable to FALSE before going into your loop, then each time through the loop test the variable and if TRUE, use ExitLoop. Take a look at HotKeySet. [u]MisterBates[/u]_____________________________________________________Suspend/Resume Windows ScreensaverWatchWindows - Window watcher/loggerUDF: Click systray menu/submenu itemsUDF: Outlook Express Folder/Message handling (+ example code)HowTo: Multiple icons in one compiled script 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