chell Posted February 5, 2007 Posted February 5, 2007 Been using autoit for a while now and this is the first time i get stuck without any ideas what so ever. So thought I'd ask for help Basically what i need help with is getting out of a FOR loop with the push of a button from the GUI. Well the code explains it better. expandcollapse popup#include <GUIConstants.au3> $window = GUICreate("Pinger", 300, 200, -1, -1) GUICtrlSetBkColor($window,0x000000) GuiSetState(@SW_SHOW) $progress = GUICtrlCreateProgress (30,70,200,20) $button = GUICtrlCreateButton ("Start",90,150,100,20) $status = GUICtrlCreateLabel ("N/A", 100, 30, 80, 20, $SS_CENTER) GUICtrlSetBkColor(-1,0x999999) $color = GUICtrlSetColor(-1,0xff0000) $ip = IniRead("targetip.ini", "host", "ip", "targetip.ini error") $s = 0 main() func main() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit(1) Case $msg = $button start() EndSelect Wend EndFunc Func start() GUICtrlSetData ($button,"Stop") $stat = "Offline" $var = Ping($ip,250) If $var Then online() Else $m = GUIGetMsg () GUICtrlSetData ($status,$stat) For $i = $s To 100 GUICtrlSetData ($progress,$i) Sleep(200) ;This is where the loop just keeps going Next if $i >100 then $s=0 start() EndIf EndIf EndFunc Func online() $stat = "Online" GUICtrlSetData ($button,"Start") GUICtrlSetData ($status,$stat) SoundPlay("online.wav") main() EndFunc Func stop() $s = 0 GUICtrlSetData ($button,"Start") GUICtrlSetData ($status,$stat & " [Stopped]") main() EndFunc I tried using solutions from other posts If statements, ONevent, Do until. Nothing seems to work. Not sure if I did it the right way tho I know there's a way to do it with hotkeys but I want that to be the last resort. Thx in advance.
eynstyne Posted February 5, 2007 Posted February 5, 2007 insert Exitloop F@m!ly Guy Fr33k! - Avatar speaks for itself__________________________________________________________________________________________ite quotes... - Is your refrigerator running? If it is, It probably runs like you...very homosexually - Christians don't believe in gravity - Geeze Brian where do you think you are, Payless?- Show me potato Salad!__________________________________________________________________________________________Programs available - Shutdown timer[indent][/indent]
chell Posted February 5, 2007 Author Posted February 5, 2007 insert Exitloop Mind showing me where? I dont want it to exit the loop until i press Stop.Thank you.
improbability_paradox Posted February 5, 2007 Posted February 5, 2007 (edited) Been using autoit for a while now and this is the first time i get stuck without any ideas what so ever. So thought I'd ask for help Basically what i need help with is getting out of a FOR loop with the push of a button from the GUI. Well the code explains it better. expandcollapse popup#include <GUIConstants.au3> $window = GUICreate("Pinger", 300, 200, -1, -1) GUICtrlSetBkColor($window,0x000000) GuiSetState(@SW_SHOW) $progress = GUICtrlCreateProgress (30,70,200,20) $button = GUICtrlCreateButton ("Start",90,150,100,20) $status = GUICtrlCreateLabel ("N/A", 100, 30, 80, 20, $SS_CENTER) GUICtrlSetBkColor(-1,0x999999) $color = GUICtrlSetColor(-1,0xff0000) $ip = IniRead("targetip.ini", "host", "ip", "targetip.ini error") $s = 0 main() func main() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit(1) Case $msg = $button start() EndSelect Wend EndFunc Func start() GUICtrlSetData ($button,"Stop") $stat = "Offline" $var = Ping($ip,250) If $var Then online() Else $m = GUIGetMsg () GUICtrlSetData ($status,$stat) For $i = $s To 100 GUICtrlSetData ($progress,$i) Sleep(200) ;This is where the loop just keeps going Next if $i >100 then $s=0 start() EndIf EndIf EndFunc Func online() $stat = "Online" GUICtrlSetData ($button,"Start") GUICtrlSetData ($status,$stat) SoundPlay("online.wav") main() EndFunc Func stop() $s = 0 GUICtrlSetData ($button,"Start") GUICtrlSetData ($status,$stat & " [Stopped]") main() EndFunc I tried using solutions from other posts If statements, ONevent, Do until. Nothing seems to work. Not sure if I did it the right way tho I know there's a way to do it with hotkeys but I want that to be the last resort. Thx in advance. A couple of things to keep in mind 1) Don't call functions from within the same function in order to "restart" or otherwise loop that function. Also, calling a function which then calls the same function which called it should be avoided. If you do this then your script will inevitably crash after i has run long enough. There are other ways of obtaining the desired results, so keep experimenting until you find them. Example using excerpt from your code Func start() ... if $i >100 then $s=0 start() EndIf EndFunc oÝ÷ Ù.².Ö¯¢'m+7ÝKjZ(¦)ì×çîËb¢x§²×w}öN±ÛazZ(§^*.¦ë!i»¶ò¢ì"YÞyÛhvp¢Øbç$~ƺ)²Æ zƧvØ^ë.)bj{¬zØ^:q/z{f¡×¡Ú"µØ}êÞÙrnëH¦·z»ayø«²Ù¶jëh×6GUICtrlSetData ($button,"Stop") For $i = $s To 100 Sleep(200) $msg = GUIGetMsg() if $msg=$button then ExitLoop Next oÝ÷ Øù^jǢ׫bÝz»h¦·¬z»Þ¶¡jwezÊÊ«è¢{k¢["Èy§îËb¢z-êí©íê'z)ð'!¶²ÁêÞr·µçr¢éÞyÛh!·¥ëÞºÇ Úö«¦åzÍ÷jëh×6Global $button = GUICtrlCreateButton ("Start",90,150,100,20) I could be wrong on this last part, but that is my assumption Edited February 5, 2007 by improbability_paradox
chell Posted February 6, 2007 Author Posted February 6, 2007 A couple of things to keep in mind 1) Don't call functions from within the same function in order to "restart" or otherwise loop that function. Also, calling a function which then calls the same function which called it should be avoided. If you do this then your script will inevitably crash after i has run long enough. There are other ways of obtaining the desired results, so keep experimenting until you find them. Example using excerpt from your code Func start() ... if $i >100 then $s=0 start() EndIf EndFunc oÝ÷ Ù.².Ö¯¢'m+7ÝKjZ(¦)ì×çîËb¢x§²×w}öN±ÛazZ(§^*.¦ë!i»¶ò¢ì"YÞyÛhvp¢Øbç$~ƺ)²Æ zƧvØ^ë.)bj{¬zØ^:q/z{f¡×¡Ú"µØ}êÞÙrnëH¦·z»ayø«²Ù¶jëh×6GUICtrlSetData ($button,"Stop") For $i = $s To 100 Sleep(200) $msg = GUIGetMsg() if $msg=$button then ExitLoop Next oÝ÷ Øù^jǢ׫bÝz»h¦·¬z»Þ¶¡jwezÊÊ«è¢{k¢["Èy§îËb¢z-êí©íê'z)ð'!¶²ÁêÞr·µçr¢éÞyÛh!·¥ëÞºÇ Úö«¦åzÍ÷jëh×6Global $button = GUICtrlCreateButton ("Start",90,150,100,20) I could be wrong on this last part, but that is my assumption Thx alot for your help. It's working fine now if $m=$button then ExitLoop & stop() That line made it all clear, i did that before but got stuck at "Where tha hell do i put the endif" lol sry :"> TYYYYYYYYYY you saved my script, was heading for the trashcan. Here's how it looks now.. expandcollapse popupGlobal $stat #include <GUIConstants.au3> $window = GUICreate("Pinger", 300, 200, -1, -1) GUICtrlSetBkColor($window,0x000000) GuiSetState(@SW_SHOW) Global $progress = GUICtrlCreateProgress (30,70,200,20) Global $button = GUICtrlCreateButton ("Start",90,150,100,20) Global $status = GUICtrlCreateLabel ("N/A", 100, 30, 80, 20, $SS_CENTER) GUICtrlSetBkColor(-1,0x999999) Global $color = GUICtrlSetColor(-1,0xff0000) Global $ip = IniRead("targetip.ini", "host", "ip", "targetip.ini error") $s = 0 main() func main() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit(1) Case $msg = $button start() EndSelect Wend EndFunc Func start() GUICtrlSetData ($button,"Stop") $stat = "Offline" While 1 $var = Ping($ip,250) If $var Then ExitLoop online() Else GUICtrlSetData ($status,$stat) For $i = $s To 100 GUICtrlSetData ($progress,$i) Sleep(200) $m = GUIGetMsg() if $m=$button then ExitLoop & stop() Next if $i >100 then $s=0 EndIf EndIf WEnd EndFunc stop() Func online() $stat = "Online" GUICtrlSetData ($button,"Start") GUICtrlSetData ($status,$stat) SoundPlay("online.wav") main() EndFunc Func stop() GUICtrlSetData ($button,"Start") GUICtrlSetData ($status,$stat & " [Stopped]") main() EndFunc
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