woleium Posted March 31, 2008 Share Posted March 31, 2008 I'm trying to cancel a loop with a button, but it doesn't work.... what do i need to do to check for events from within the loop? $btn_cancel = GUICtrlCreateButton("Cancel", 142, 30, 80, 22, 0) Global $loopcount Do If @error Then ExitLoop ;do some stuff $loopcount = $loopcount + 1 Sleep (200) Until $loopcount = 50; = 10 seconds Func Cancel_pressed() msgbox (48,"ERROR","Canx" ) $loopcount=49 EndFunc Link to comment Share on other sites More sharing options...
d4rk Posted March 31, 2008 Share Posted March 31, 2008 $btn_cancel = GUICtrlCreateButton("Cancel", 142, 30, 80, 22, 0) Global $loopcount Do If @error Then ExitLoop ;do some stuff $loopcount = $loopcount + 1 Sleep (200) Until $loopcount = 50; = 10 seconds Func Cancel_pressed() msgbox (48,"ERROR","Canx" ) ;$loopcount=49 exitloop EndFunc [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
monoceres Posted March 31, 2008 Share Posted March 31, 2008 (edited) If you haven't already, you must define the event for the button, like this: GUICtrlSetOnEvent($btn_cancel,"Cancel_pressed") Edited March 31, 2008 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
monoceres Posted March 31, 2008 Share Posted March 31, 2008 (edited) Func Cancel_pressed() msgbox (48,"ERROR","Canx" ) ;$loopcount=49exitloopEndFuncThe only thing that will do is generate an error since you cannot use ExitLoop outside a loop! Edited March 31, 2008 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
d4rk Posted March 31, 2008 Share Posted March 31, 2008 yes . sure [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
woleium Posted March 31, 2008 Author Share Posted March 31, 2008 If you haven't already, you must define the event for the button, like this: GUICtrlSetOnEvent($btn_cancel,"Cancel_pressed")Yep, i forgot to include that in the OP, but it's there.Really the problem is that when in the loop the exe seems to stop polling, or listening to events from the GUI. Any ideas would be greatly appreciated...W. Link to comment Share on other sites More sharing options...
d4rk Posted March 31, 2008 Share Posted March 31, 2008 use this, i love simple while 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop elseif $msg=$btn_cancel Then msgbox (48,"ERROR","Canx" ) $loopcount=49 EndIf WEnd [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
monoceres Posted March 31, 2008 Share Posted March 31, 2008 Well then some more of your script is required as this whole thing seems strange. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
weaponx Posted March 31, 2008 Share Posted March 31, 2008 #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode GUICreate("GUI", 200, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "ClickClose") $label = GUICtrlCreateLabel("", 30, 10) $okbutton = GUICtrlCreateButton("STOP", 70, 50, 60) GUICtrlSetOnEvent($okbutton, "ClickStop") GUISetState(@SW_SHOW) ;Define sentinel to break loop Global $break = false $count = 0 ;Count forever Do GuiCtrlSetData($label,$count) $count += 1 Sleep(1000) Until $break While 1 Sleep(1000) ; Idle around WEnd Func ClickStop() $break = true EndFunc Func ClickClose() Exit EndFunc Link to comment Share on other sites More sharing options...
woleium Posted March 31, 2008 Author Share Posted March 31, 2008 (edited) Argh, I still con't get it to work. Here is the stripped down version, complete witn non working cancel button: Please help! I'm pulling my hair out on this one! expandcollapse popup#include <GUIConstants.au3> ; Change to OnEvent mode Opt("GUIOnEventMode", 1) ; Define Globals & Dim's global $break = False ; Setup the Gui $GUIp = GUICreate("",360,130, Default, Default, $WS_POPUP) $res_select = GUICtrlCreateCombo("Full Screen", 30, 30, 100, 25,$CBS_DROPDOWNLIST) GUICtrlSetData($res_select,"640 x 480|800 x 600|1024 x 768|1280 x 1024|1600 x 1200") $btn_connect = GUICtrlCreateButton("Connect", 142, 30, 80, 22, 0) GUICtrlSetOnEvent($btn_connect, "Btn_Connect") GuiSetState() While 1 Sleep(1000) ; Idle around WEnd ;################################################# ;# Functions ;################################################# Func Btn_Connect() GUICtrlSetState($res_select,$GUI_HIDE) GUICtrlSetState($btn_connect,$GUI_HIDE) $btn_cancel = GUICtrlCreateButton("Cancel", 142, 30, 80, 22, 0) ;$btn_cancel = GUICtrlCreateButton("Cancel", 142, 50, 80, 22, 0) GUICtrlSetOnEvent($btn_cancel, "click_canx") global $prog_con = GuiCtrlCreateProgress(31, 31, 98, 18) global $prog_con_val GuiCtrlSetData($prog_con, $prog_con_val) Global $loopcount dim $gotping = 0 Do $loopcount = $loopcount + 1 $prog_con_val = $prog_con_val + 2 GuiCtrlSetData($prog_con, $prog_con_val) Sleep (200) Until $break OR $loopcount = 50; = 10 seconds Exit EndFunc Func click_canx() MsgBox(0,"","canx clicked") $break = true EndFunc Edited March 31, 2008 by woleium Link to comment Share on other sites More sharing options...
monoceres Posted March 31, 2008 Share Posted March 31, 2008 (edited) Ok, here's the deal you will not recieve events when you're already in a function triggered by an event. But don't worry, here's a working version (though I just did a copy and paste so this will not work too well ) expandcollapse popup#include <GUIConstants.au3> ; Change to OnEvent mode Opt("GUIOnEventMode", 1) ; Define Globals & Dim's Global $break = False, $check = False ; Setup the Gui $GUIp = GUICreate("", 360, 130, Default, Default, $WS_POPUP) $btn_cancel = GUICtrlCreateButton("Cancel", 142, 30, 80, 22, 0) ;$btn_cancel = GUICtrlCreateButton("Cancel", 142, 50, 80, 22, 0) GUICtrlSetOnEvent($btn_cancel, "click_canx") GUICtrlSetState(-1, $GUI_HIDE) $res_select = GUICtrlCreateCombo("Full Screen", 30, 30, 100, 25, $CBS_DROPDOWNLIST) GUICtrlSetData($res_select, "640 x 480|800 x 600|1024 x 768|1280 x 1024|1600 x 1200") $btn_connect = GUICtrlCreateButton("Connect", 142, 30, 80, 22, 0) GUICtrlSetOnEvent($btn_connect, "Btn_Connect") GUISetState() While 1 Sleep(100) ; Idle around If $check Then GUICtrlSetState($res_select, $GUI_HIDE) GUICtrlSetState($btn_connect, $GUI_HIDE) $btn_cancel = GUICtrlCreateButton("Cancel", 142, 30, 80, 22, 0) ;$btn_cancel = GUICtrlCreateButton("Cancel", 142, 50, 80, 22, 0) GUICtrlSetOnEvent($btn_cancel, "click_canx") Global $prog_con = GUICtrlCreateProgress(31, 31, 98, 18) Global $prog_con_val GUICtrlSetData($prog_con, $prog_con_val) Global $loopcount Dim $gotping = 0 Do $loopcount = $loopcount + 1 $prog_con_val = $prog_con_val + 2 GUICtrlSetData($prog_con, $prog_con_val) Sleep(200) ;~ msgbox(0,"","") Until $break Or $loopcount = 50; = 10 seconds Exit EndIf WEnd ;################################################# ;# Functions ;################################################# Func Btn_Connect() $check = True EndFunc ;==>Btn_Connect Func click_canx() MsgBox(0, "", "canx clicked") $break = True EndFunc ;==>click_canx Edited March 31, 2008 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
weaponx Posted March 31, 2008 Share Posted March 31, 2008 (edited) I think this is a limitation of OnEvent mode. If you enter a loop inside a function, event triggers are ignored. You can verify this by trying to click the X to close the window. I had to move sentinel-controlled loops outside any functions for my Checkers game due to this.You aren't the first to have this problem:http://www.autoitscript.com/forum/index.ph...nside++function Edited March 31, 2008 by weaponx Link to comment Share on other sites More sharing options...
monoceres Posted March 31, 2008 Share Posted March 31, 2008 (edited) I feel so guilty for posting the extremely dirty source above so here's a new one which is a loooot mer cleaner expandcollapse popup#include <GUIConstants.au3> ; Change to OnEvent mode Opt("GUIOnEventMode", 1) ; Define Globals & Dim's Global $break = False, $activate = False, $active=False Global $prog_con Global $prog_con_val Global $gotping = 0 ; Setup the Gui $GUIp = GUICreate("", 360, 130, Default, Default, $WS_POPUP) $btn_cancel = GUICtrlCreateButton("Cancel", 142, 30, 80, 22, 0) ;$btn_cancel = GUICtrlCreateButton("Cancel", 142, 50, 80, 22, 0) GUICtrlSetOnEvent($btn_cancel, "click_canx") GUICtrlSetState(-1, $GUI_HIDE) $res_select = GUICtrlCreateCombo("Full Screen", 30, 30, 100, 25, $CBS_DROPDOWNLIST) GUICtrlSetData($res_select, "640 x 480|800 x 600|1024 x 768|1280 x 1024|1600 x 1200") $btn_connect = GUICtrlCreateButton("Connect", 142, 30, 80, 22, 0) GUICtrlSetOnEvent($btn_connect, "Btn_Connect") GUISetState() While 1 Sleep(100) ; Idle around If $activate Then $timer=TimerInit() GUICtrlSetState($res_select, $GUI_HIDE) GUICtrlSetState($btn_connect, $GUI_HIDE) $btn_cancel = GUICtrlCreateButton("Cancel", 142, 30, 80, 22, 0) GUICtrlSetOnEvent($btn_cancel, "click_canx") $activate=False $active=True $prog_con = GUICtrlCreateProgress(31, 31, 98, 18) GUICtrlSetLimit(-1,100,0) EndIf If $active Then GUICtrlSetData($prog_con, $prog_con_val) $prog_con_val = TimerDiff($timer)/50 GUICtrlSetData($prog_con, $prog_con_val) If TimerDiff($timer)>5000 Or $break=True Then Exit EndIf EndIf WEnd ;################################################# ;# Functions ;################################################# Func Btn_Connect() $activate = True EndFunc ;==>Btn_Connect Func click_canx() MsgBox(0, "", "canx clicked") $break = True EndFunc ;==>click_canx Edited March 31, 2008 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
woleium Posted March 31, 2008 Author Share Posted March 31, 2008 Ok, here's the deal you will not recieve events when you're already in a function triggered by an event. But don't worry, here's a working version (though I just did a copy and paste so this will not work too well ) expandcollapse popup#include <GUIConstants.au3> ; Change to OnEvent mode Opt("GUIOnEventMode", 1) ; Define Globals & Dim's Global $break = False, $check = False ; Setup the Gui $GUIp = GUICreate("", 360, 130, Default, Default, $WS_POPUP) $btn_cancel = GUICtrlCreateButton("Cancel", 142, 30, 80, 22, 0) ;$btn_cancel = GUICtrlCreateButton("Cancel", 142, 50, 80, 22, 0) GUICtrlSetOnEvent($btn_cancel, "click_canx") GUICtrlSetState(-1, $GUI_HIDE) $res_select = GUICtrlCreateCombo("Full Screen", 30, 30, 100, 25, $CBS_DROPDOWNLIST) GUICtrlSetData($res_select, "640 x 480|800 x 600|1024 x 768|1280 x 1024|1600 x 1200") $btn_connect = GUICtrlCreateButton("Connect", 142, 30, 80, 22, 0) GUICtrlSetOnEvent($btn_connect, "Btn_Connect") GUISetState() While 1 Sleep(100) ; Idle around If $check Then GUICtrlSetState($res_select, $GUI_HIDE) GUICtrlSetState($btn_connect, $GUI_HIDE) $btn_cancel = GUICtrlCreateButton("Cancel", 142, 30, 80, 22, 0) ;$btn_cancel = GUICtrlCreateButton("Cancel", 142, 50, 80, 22, 0) GUICtrlSetOnEvent($btn_cancel, "click_canx") Global $prog_con = GUICtrlCreateProgress(31, 31, 98, 18) Global $prog_con_val GUICtrlSetData($prog_con, $prog_con_val) Global $loopcount Dim $gotping = 0 Do $loopcount = $loopcount + 1 $prog_con_val = $prog_con_val + 2 GUICtrlSetData($prog_con, $prog_con_val) Sleep(200) ;~ msgbox(0,"","") Until $break Or $loopcount = 50; = 10 seconds Exit EndIf WEnd ;################################################# ;# Functions ;################################################# Func Btn_Connect() $check = True EndFunc ;==>Btn_Connect Func click_canx() MsgBox(0, "", "canx clicked") $break = True EndFunc ;==>click_canx YAY! thank you thank you thank you Link to comment Share on other sites More sharing options...
weaponx Posted March 31, 2008 Share Posted March 31, 2008 This solution works but unfortunately it really limits what you can do with your script. This only allows one sentinel-controlled loop in your script since it has to be outside of any function. Maybe Jos can chime in with a better idea. Link to comment Share on other sites More sharing options...
monoceres Posted March 31, 2008 Share Posted March 31, 2008 This solution works but unfortunately it really limits what you can do with your script. This only allows one sentinel-controlled loop in your script since it has to be outside of any function. Maybe Jos can chime in with a better idea.I really don't see how it limits your scripts because you can always place you loops in the main loop and use an If statement to start them.Or am I missing something? Broken link? PM me and I'll send you the file! 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