youtuber Posted February 9, 2018 Share Posted February 9, 2018 Hi friends, if my $error variable is 1 I want to exit the loop For $m = 0 To UBound($a) - 1 How do I do it? Thank you expandcollapse popupGlobal $oMyError = ObjEvent("AutoIt.Error", "httperror") Global $error = 0 Local $a[3] = ["http://127.0.1.1", "http://127.0.0.2", "http://127.0.0.3"] Local $b[2] = ["Post1Test1", "Post1Test2"] Local $c[2] = ["Post2Test1", "Post2Test2"] For $m = 0 To UBound($a) - 1 For $X = 0 To UBound($b) - 1 For $i = 0 To UBound($c) - 1 $con = Connect($a[$m], $b[$X] & $c[$i]) ConsoleWrite(" Line Connect : " & @ScriptLineNumber & " -> " & $a[$m] & " " & $b[$X] & " " & $c[$i] & @CRLF) If $error = 1 Then ExitLoop EndIf Next Next Next Func Connect($Url, $PostData = '') Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $Url, False) $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0") $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3") $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.SetRequestHeader("X-Requested-With", "XMLHttpRequest") $oHTTP.Send($PostData) If @error Then ConsoleWrite("Error connection" & @CRLF) $error = 1 $oHTTP = 0 Return SetError(1) EndIf ConsoleWrite(" Line : " & @ScriptLineNumber & " -> Status : " & $oHTTP.Status & @CRLF) If $oHTTP.Status = 200 Then Local $sReceived = $oHTTP.ResponseText $oHTTP = Null Return $sReceived EndIf $oHTTP = Null Return -1 EndFunc ;==>Connect Func httperror() ConsoleWrite("http error" & @CRLF) $oMyError.Clear Return SetError(1) EndFunc ;==>httperror Link to comment Share on other sites More sharing options...
BrewManNH Posted February 9, 2018 Share Posted February 9, 2018 Get rid of or move the ConsoleWrite before the check of @error youtuber 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
youtuber Posted February 9, 2018 Author Share Posted February 9, 2018 Yes I checked with ConsoleWrite, but the error value turns to 1 but does not exit the loop For $m = 0 To UBound($a) - 1 For $X = 0 To UBound($b) - 1 For $i = 0 To UBound($c) - 1 $con = Connect($a[$m], $b[$X] & $c[$i]) ConsoleWrite(" Line Connect : " & @ScriptLineNumber & " -> " & " Error value " & $error & " " & $a[$m] & " " & $b[$X] & " " & $c[$i] & @CRLF) If $error = 1 Then ExitLoop EndIf Next Next Next Link to comment Share on other sites More sharing options...
Danp2 Posted February 9, 2018 Share Posted February 9, 2018 Remove the ConsoleWrite in the Connect function. Otherwise, you lose the value of @error. youtuber 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
BrewManNH Posted February 9, 2018 Share Posted February 9, 2018 The ConsoleWrite is resetting the error condition, so it will never exit the loop. Hence, get rid of it, or move it elsewhere in your script. youtuber 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
youtuber Posted February 9, 2018 Author Share Posted February 9, 2018 (edited) @Danp2 @BrewManNH still no change at all expandcollapse popupGlobal $oMyError = ObjEvent("AutoIt.Error", "httperror") Global $error = 0 Local $a[3] = ["http://127.0.1.1", "http://127.0.0.2", "http://127.0.0.3"] Local $b[2] = ["Post1Test1", "Post1Test2"] Local $c[2] = ["Post2Test1", "Post2Test2"] For $m = 0 To UBound($a) - 1 For $X = 0 To UBound($b) - 1 For $i = 0 To UBound($c) - 1 $con = Connect($a[$m], $b[$X] & $c[$i]) ConsoleWrite(" Line Connect : " & @ScriptLineNumber & " -> " & " Error value " & $error & " " & $a[$m] & " " & $b[$X] & " " & $c[$i] & @CRLF) If $error = 1 Then ExitLoop Next Next Next Func Connect($Url, $PostData = '') Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $Url, False) $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0") $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3") $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.SetRequestHeader("X-Requested-With", "XMLHttpRequest") $oHTTP.Send($PostData) If @error Then $error = 1 $oHTTP = 0 Return SetError(1) EndIf If $oHTTP.Status = 200 Then Local $sReceived = $oHTTP.ResponseText $oHTTP = Null Return $sReceived EndIf $oHTTP = Null Return -1 EndFunc ;==>Connect Func httperror() $oMyError.Clear Return SetError(1) EndFunc ;==>httperror Edited February 9, 2018 by youtuber Link to comment Share on other sites More sharing options...
Danp2 Posted February 9, 2018 Share Posted February 9, 2018 Post the results from the Scite output window so that we can see where the error occurred. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
youtuber Posted February 9, 2018 Author Share Posted February 9, 2018 @Danp2 Spoiler Link to comment Share on other sites More sharing options...
Danp2 Posted February 9, 2018 Share Posted February 9, 2018 You'll need to provide the optional level parameter to exit all three loops -- ExitLoop 3 youtuber 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
youtuber Posted February 9, 2018 Author Share Posted February 9, 2018 @Danp2 but if it is so? Local $a[4] = ["http://127.0.0.1", "http://127.0.0.2", "http://127.0.0.3", "http://127.0.0.1"] Spoiler Link to comment Share on other sites More sharing options...
Danp2 Posted February 9, 2018 Share Posted February 9, 2018 @youtuber What's the issue? The ConsoleWrite comes before the line with ExitLoop, so it appears to me that the loop exited as planned. youtuber 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
JohnOne Posted February 9, 2018 Share Posted February 9, 2018 For $m = 0 To UBound($a) - 1 For $X = 0 To UBound($b) - 1 For $i = 0 To UBound($c) - 1 $con = Connect($a[$m], $b[$X] & $c[$i]) $error = @error ; <============================== ConsoleWrite(" Line Connect : " & @ScriptLineNumber & " -> " & $a[$m] & " " & $b[$X] & " " & $c[$i] & @CRLF) If $error = 1 Then ExitLoop EndIf Next Next Next youtuber 1 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...
youtuber Posted February 9, 2018 Author Share Posted February 9, 2018 @Danp2 the loop does not continue here Local $a[5] = ["http://127.0.0.1", "http://127.0.0.2", "http://127.0.0.3", "http://127.0.0.1", "https://www.autoitscript.com"] Spoiler Link to comment Share on other sites More sharing options...
Danp2 Posted February 9, 2018 Share Posted February 9, 2018 2 hours ago, youtuber said: if my $error variable is 1 I want to exit the loop For $m = 0 To UBound($a) - 1 How do I do it? This is what you originally stated. That is the outer-most loop, so the looping stops entirely when you use the code I posted. If you want that outer loop to continue, then reduce the ExitLoop value by 1. youtuber 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
youtuber Posted February 9, 2018 Author Share Posted February 9, 2018 @Danp2 Thank you, I think it's true expandcollapse popupGlobal $oMyError = ObjEvent("AutoIt.Error", "httperror") Global $error = 0 Local $a[5] = ["http://127.0.0.1", "http://127.0.0.2", "http://127.0.0.3", "http://127.0.0.1", "https://www.autoitscript.com"] Local $b[2] = ["Post1Test1", "Post1Test2"] Local $c[2] = ["Post2Test1", "Post2Test2"] For $m = 0 To UBound($a) - 1 For $X = 0 To UBound($b) - 1 For $i = 0 To UBound($c) - 1 $con = Connect($a[$m], $b[$X] & $c[$i]) $error = @error ; <============================== ConsoleWrite(" Line Connect : " & @ScriptLineNumber & " -> " & $a[$m] & " " & $b[$X] & " " & $c[$i] & @CRLF) If $error = 1 Then ExitLoop 2 EndIf Next Next Next Func Connect($Url, $PostData = '') Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $Url, False) $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0") $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3") $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.SetRequestHeader("X-Requested-With", "XMLHttpRequest") $oHTTP.Send($PostData) If @error Then $error = 1 $oHTTP = 0 Return SetError(1) EndIf If $oHTTP.Status = 200 Then Local $sReceived = $oHTTP.ResponseText $oHTTP = Null Return $sReceived EndIf $oHTTP = Null Return -1 EndFunc ;==>Connect Func httperror() $oMyError.Clear Return SetError(1) EndFunc ;==>httperror 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