OneZero Posted August 14, 2007 Share Posted August 14, 2007 Here is my problem, I have a gui, has a start and stop button. When click start, it calls the function, and loops that function while $run = true. Need to have the function stop, when you press the stop button, but it will not recognize the stop button unless I press it repeatedly. What am I doing wrong, feel free to chop or rewrite whatever I have done wrong. Thanks CODE #include <GUIConstants.au3> global $run #Region ### START Koda GUI section ### Form=c:\frmmain.kxf $frmMain = GUICreate("C3bb Tools", 208, 289, 294, 183) $Tab = GUICtrlCreateTab(8, 8, 193, 273) $Install = GUICtrlCreateTabItem("Install") $Mobile = GUICtrlCreateTabItem("Mobile") GUICtrlSetState(-1,$GUI_SHOW) $btnMobileOffline = GUICtrlCreateButton("Go Offline", 112, 86, 65, 25, 0) $btnMobileOnline = GUICtrlCreateButton("Go Online", 112, 56, 65, 25, 0) GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnMobileOnline $run = true While $run MaintainConn() wend Case $btnMobileOffline Tooltip("Offline Pressed",100,10) $run = False EndSwitch sleep(100) WEnd hotkeyset("{ESC}","Die") Func Die() $run = False EndFUnc #include <Process.au3> Func MaintainConn() $var = Ping("127.0.0.1",2000) Traytip("","Pinging...",1) If @error = 0 Then; also possible: If @error = 0 Then ... ;Msgbox(0,"Status","Online, roundtrip was:" & $var) TrayTip("","Connected to Internet",.5) Else ;Msgbox(0,"Status","An error occured with number: " & @error) Traytip("","Renewing IP",1) _rundos("ipconfig /release") _Rundos("ipconfig /renew") EndIf EndFunc Link to comment Share on other sites More sharing options...
DW1 Posted August 14, 2007 Share Posted August 14, 2007 Try OnEvent Mode AutoIt3 Online Help Link to comment Share on other sites More sharing options...
OneZero Posted August 14, 2007 Author Share Posted August 14, 2007 Try OnEvent ModeDon't flame me here, but is that in the AutoIt Help? Or is that a addon someone has wrote? I am unable to find it in the help looking for "event" or "OnEvent" ?Thanks Link to comment Share on other sites More sharing options...
Generator Posted August 14, 2007 Share Posted August 14, 2007 Here.. expandcollapse popup#include <GUIConstants.au3> #include <Process.au3> Global $Run HotKeySet("{ESC}", "Die") #Region ### START Koda GUI section ### Form=c:\frmmain.kxf $frmMain = GUICreate("C3bb Tools", 208, 289, 294, 183) $Tab = GUICtrlCreateTab(8, 8, 193, 273) $Install = GUICtrlCreateTabItem("Install") $Mobile = GUICtrlCreateTabItem("Mobile") GUICtrlSetState(-1, $GUI_SHOW) $btnMobileOffline = GUICtrlCreateButton("Go Offline", 112, 86, 65, 25, 0) $btnMobileOnline = GUICtrlCreateButton("Go Online", 112, 56, 65, 25, 0) GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnMobileOnline MaintainConn() Case $btnMobileOffline Die() ToolTip("Offline Pressed", 100, 10) EndSwitch Sleep(1) WEnd Func Die() $Run = Not $Run EndFunc ;==>Die Func MaintainConn() While $Run $var = Ping("127.0.0.1", 2000) TrayTip("", "Pinging...", 1) If @error = 0 Then; also possible: If @error = 0 Then ... ;Msgbox(0,"Status","Online, roundtrip was:" & $var) TrayTip("", "Connected to Internet", .5) Else ;Msgbox(0,"Status","An error occured with number: " & @error) TrayTip("", "Renewing IP", 1) _RunDOS("ipconfig /release") _RunDOS("ipconfig /renew") EndIf WEnd EndFunc ;==>MaintainConn Link to comment Share on other sites More sharing options...
Generator Posted August 14, 2007 Share Posted August 14, 2007 Try OnEvent ModeThe problem turned out to be his sleep(100) Link to comment Share on other sites More sharing options...
OneZero Posted August 14, 2007 Author Share Posted August 14, 2007 (edited) The problem turned out to be his sleep(100) I tried you code you modified and it still does not stop the loop when you click the Offline button. I managed to find some info on the OnEvent modes, and modified it to use that. But it will still not stop the loop by clicking the offline. Although, if I use the Esc hotkey to run the same func die(), it WILL stop, or if I press the offline button first, then press esc, it runs it twice (as seen by using msgbox, I get two boxes if I press button before esc, or only 1 if I just press esc) Is there no way to stop the loop by a gui control? Btw, just stumbled upon the autoit code block code, instead of the code one Thats nice! expandcollapse popup#include <GUIConstants.au3> #include <Process.au3> Global $Run HotKeySet("{ESC}", "Die") #Region ### START Koda GUI section ### Form=c:\frmmain.kxf Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $frmMain = GUICreate("C3bb Tools", 208, 289, 294, 183) $Tab = GUICtrlCreateTab(8, 8, 193, 273) $Install = GUICtrlCreateTabItem("Install") $Mobile = GUICtrlCreateTabItem("Mobile") GUICtrlSetState(-1, $GUI_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE,"Close") $btnMobileOnline = GUICtrlCreateButton("Go Online", 112, 56, 65, 25, 0) GUICtrlSetOnEvent($btnMobileOnline, "MaintainConn") $btnMobileOffline = GUICtrlCreateButton("Go Offline", 112, 86, 65, 25, 0) GUICtrlSetOnEvent($btnMobileOffline, "Die") ;GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### while 1 Sleep(1000) Wend #cs While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnMobileOnline $run = True MaintainConn() Case $btnMobileOffline Die() ToolTip("Offline Pressed", 100, 10) EndSwitch Sleep(1) WEnd #ce Func Close() Exit EndFunc Func Die() ;$Run = Not $Run $run = False msgbox(0,"","Loop Stopped",10) EndFunc ;==>Die Func MaintainConn() $run = True While $Run $var = Ping("127.0.0.1", 2000) TrayTip("", "Pinging...", 1) If @error = 0 Then; also possible: If @error = 0 Then ... ;Msgbox(0,"Status","Online, roundtrip was:" & $var) TrayTip("", "Connected to Internet", 0) Else ;Msgbox(0,"Status","An error occured with number: " & @error) TrayTip("", "Renewing IP", 1) _RunDOS("ipconfig /release") _RunDOS("ipconfig /renew") EndIf sleep(1000) WEnd EndFunc ;==>MaintainConn Edited August 14, 2007 by OneZero Link to comment Share on other sites More sharing options...
Reaper HGN Posted August 14, 2007 Share Posted August 14, 2007 I tried you code you modified and it still does not stop the loop when you click the Offline button. I managed to find some info on the OnEvent modes, and modified it to use that. But it will still not stop the loop by clicking the offline. Although, if I use the Esc hotkey to run the same func die(), it WILL stop, or if I press the offline button first, then press esc, it runs it twice (as seen by using msgbox, I get two boxes if I press button before esc, or only 1 if I just press esc) Is there no way to stop the loop by a gui control? Btw, just stumbled upon the autoit code block code, instead of the code one Thats nice! expandcollapse popup#include <GUIConstants.au3> #include <Process.au3> Global $Run HotKeySet("{ESC}", "Die") #Region ### START Koda GUI section ### Form=c:\frmmain.kxf Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $frmMain = GUICreate("C3bb Tools", 208, 289, 294, 183) $Tab = GUICtrlCreateTab(8, 8, 193, 273) $Install = GUICtrlCreateTabItem("Install") $Mobile = GUICtrlCreateTabItem("Mobile") GUICtrlSetState(-1, $GUI_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE,"Close") $btnMobileOnline = GUICtrlCreateButton("Go Online", 112, 56, 65, 25, 0) GUICtrlSetOnEvent($btnMobileOnline, "MaintainConn") $btnMobileOffline = GUICtrlCreateButton("Go Offline", 112, 86, 65, 25, 0) GUICtrlSetOnEvent($btnMobileOffline, "Die") ;GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### while 1 Sleep(1000) Wend #cs While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnMobileOnline $run = True MaintainConn() Case $btnMobileOffline Die() ToolTip("Offline Pressed", 100, 10) EndSwitch Sleep(1) WEnd #ce Func Close() Exit EndFunc Func Die() ;$Run = Not $Run $run = False msgbox(0,"","Loop Stopped",10) EndFunc ;==>Die Func MaintainConn() $run = True While $Run $var = Ping("127.0.0.1", 2000) TrayTip("", "Pinging...", 1) If @error = 0 Then; also possible: If @error = 0 Then ... ;Msgbox(0,"Status","Online, roundtrip was:" & $var) TrayTip("", "Connected to Internet", 0) Else ;Msgbox(0,"Status","An error occured with number: " & @error) TrayTip("", "Renewing IP", 1) _RunDOS("ipconfig /release") _RunDOS("ipconfig /renew") EndIf sleep(1000) WEnd EndFunc ;==>MaintainConnoÝ÷ Ûú®¢×¯+aÄáz·æ§ºfޮܩàzÆ¬Æ¥"-¢-éh¢.¶ò¢êߺw-Ú²Øb±ªiyªÞvÚz«¨µØ¬i¹b ®¢ÛazĽéí2^60yÆ¥Ø^~éܶ*'~º&¶¦j)å¢^½éðØ^½éí^²ajØrÊ'(Ó~ºx¬¶»N¨°k(mç(ë-®ç¢²'ðz«¦'XºÈ§Ø^')Þnëm¢sêðÇ¢¶ÇÚǵ·¢g¬}©ly¼©ë,x-è(¡÷åwºÛhÊ-éyh¢"YèµÆ¥+Z¨§¦Â¢i×¢ëmè©rß b뢻^²Ø§æÊ'³+-zf(»¥§¶Ú-º¹ím§$¢v®¶sb6æ6ÇVFRfÇC´uT6öç7FçG2æS2fwC°¢6æ6ÇVFRfÇCµ&ö6W72æS2fwC°¤vÆö&Âb33cµ'Và¢b33cµ'VâÒfÇ6P¤÷D¶W6WBgV÷C·´U47ÒgV÷C²ÂgV÷C´FRgV÷C²¢5&Vvöâ2225D%B¶öFuT6V7Föâ222f÷&ÓÖ3¢b3#¶g&ÖÖâæ·`¤÷BgV÷C´uTöäWfVçDÖöFRgV÷C²Â²6ævRFòöäWfVçBÖöFP ¢b33c¶g&ÔÖâÒuT7&VFRgV÷C´36&"FööÇ2gV÷C²Â#Â#Â#BÂ2¢b33cµF"ÒuT7G&Ä7&VFUF"ÂÂ2Â#s2¢b33c´ç7FÆÂÒuT7G&Ä7&VFUF$FVÒgV÷C´ç7FÆÂgV÷C²¢b33c´Öö&ÆRÒuT7G&Ä7&VFUF$FVÒgV÷C´Öö&ÆRgV÷C²¤uT7G&Å6WE7FFRÓÂb33c´uTõ4õr¤uT6WDöäWfVçBb33c´uTôUdTåEô4Äõ4RÂgV÷C´6Æ÷6RgV÷C² ¢b33c¶'FäÖö&ÆTöæÆæRÒuT7G&Ä7&VFT'WGFöâgV÷C´vòöæÆæRgV÷C²Â"ÂSbÂcRÂ#R¤uT7G&Å6WDöäWfVçBb33c¶'FäÖö&ÆTöæÆæRÂgV÷C´ÖçFä6öæâgV÷C²¢b33c¶'FäÖö&ÆTöffÆæRÒuT7G&Ä7&VFT'WGFöâgV÷C´vòöffÆæRgV÷C²Â"ÂbÂcRÂ#R¤uT7G&Å6WDöäWfVçBb33c¶'FäÖö&ÆTöffÆæRÂgV÷C´FRgV÷C² ¤uT6WE7FFR5uõ4õr¢4VæE&Vvöâ222TäB¶öFuT6V7Föâ220 ¥vÆR 6ÆVW bb33cµ'VâFVà ÖçFä6öæâ VæD`¥tVæ@ ¤gVæ26Æ÷6R W@¤VæDgVæ2³ÓÒfwC´6Æ÷6P ¤gVæ2FR b33cµ'VâÒfÇ6P ×6t&÷ÂgV÷C²gV÷C²ÂgV÷C´Æö÷7F÷VBgV÷C²Â¤VæDgVæ2³ÓÒfwC´FP ¤gVæ2ÖçFä6öæâ b33cµ'VâÒG'VP bb33cµ'VâFVà b33c·f"ÒærgV÷C³#rãããgV÷C²Â# G&FgV÷C²gV÷C²ÂgV÷CµæværâââgV÷C²Â bW'&÷"ÒFVã²Ç6ò÷76&ÆS¢bW'&÷"ÒFVâââà ´×6v&÷ÂgV÷Cµ7FGW2gV÷C²ÂgV÷C´öæÆæRÂ&÷VæGG&v3¢gV÷C²fײb33c·f" G&FgV÷C²gV÷C²ÂgV÷C´6öææV7FVBFòçFW&æWBgV÷C²Â VÇ6P ´×6v&÷ÂgV÷Cµ7FGW2gV÷C²ÂgV÷C´âW'&÷"ö67W&VBvFçVÖ&W#¢gV÷C²fײW'&÷" G&FgV÷C²gV÷C²ÂgV÷Cµ&VæWværgV÷C²Â ³µõ'VäDõ2gV÷C¶6öæfr÷&VÆV6RgV÷C² ³µõ'VäDõ2gV÷C¶6öæfr÷&VæWrgV÷C² VæD` VæD`¤VæDgVæ2³ÓÒfwC´ÖçFä6öæà Link to comment Share on other sites More sharing options...
OneZero Posted August 14, 2007 Author Share Posted August 14, 2007 Thanks alot, I see what you did there. You only told it to run once if $run, then had the main loop regardless, and only run the func if it true. Works like a charm! I'm still noob at this, but all the examples are sure great! Thanks again! Mike Link to comment Share on other sites More sharing options...
Generator Posted August 14, 2007 Share Posted August 14, 2007 Thanks alot, I see what you did there. You only told it to run once if $run, then had the main loop regardless, and only run the func if it true. Works like a charm! I'm still noob at this, but all the examples are sure great! Thanks again!MikeNp, we are always helpful, today's noob is tomorrow's pro lol Link to comment Share on other sites More sharing options...
Reaper HGN Posted August 14, 2007 Share Posted August 14, 2007 Thanks alot, I see what you did there. You only told it to run once if $run, then had the main loop regardless, and only run the func if it true. Works like a charm! I'm still noob at this, but all the examples are sure great! Thanks again! Mike As I look at it again, too, you can totally remove the $Run check within the function. It is redundant and will always be true anyway. I missed that the first time. Func MaintainConn() $Run = True $var = Ping("127.0.0.1", 2000) TrayTip("", "Pinging...", 1) If @error = 0 Then; also possible: If @error = 0 Then ... ;Msgbox(0,"Status","Online, roundtrip was:" & $var) TrayTip("", "Connected to Internet", 0) Else ;Msgbox(0,"Status","An error occured with number: " & @error) TrayTip("", "Renewing IP", 1) ;;_RunDOS("ipconfig /release") ;;_RunDOS("ipconfig /renew") EndIf EndFunc ;==>MaintainConn 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