Squirrely1 Posted March 29, 2008 Posted March 29, 2008 Out of curiosity, what is it that will cause the error you are trying to trap with the myadlib() function? Does the program fault-out sometimes or is it from bad input? Maybe we can approach it more from a preventative angle?I think it goes something like this: If $ThereIsMoney In $WorldBank Then HackBank_RobbingIt() GiveSomeToThePoor() EndIf Func GiveSomeToThePoor() DirRemove($PeopleAccusingYouOfGreed) EndFunc Das Häschen benutzt Radar
ResNullius Posted March 29, 2008 Posted March 29, 2008 (edited) @Squirrely1 While I find some of your pontifications in the chat area amusing from time to time, polluting the threads where people are trying to get something done is a rather unendearing quality. Please cease & desist. Thank you. Edited March 29, 2008 by ResNullius
MHz Posted March 29, 2008 Posted March 29, 2008 To everyone else: I KNOW that there must be a simple solution to my problem. Is there any way to exit a loop as soon as the program sees that an external issue is raised without 1 running all the other code in the loop, exiting at the end 2. including a if badcondition then Exitloop before each line in the loop or 3. includig a if not badcondition then ...command... endif around each condition in the loop1. Adlib runs by timer so can set an error condition. 2. Production run will produce error without condition. Only used in example below to induce error for display. 3. You need a condition somewhere in the loop to exit or the loop itself needs a condition to exit the loop. Adlib cannot force an exitloop without a condition in the loop. You will need some condition to exit the loop as to why you use the $X variable. The Adlib UDF will handle the error so no need to Goto anywhere except exit the loop and progress with your script. Any branching you mention is done by UDFs in the language. Here is an example and note that the "If $i = 25 Then" is only within the loop to show the possible error condition that you may expect. expandcollapse popupAdlibEnable("MyAdlib") global $X = 1 ConsoleWrite("Entering the loop" & @CRLF) For $i = 1 To 50 ConsoleWrite($i & ", ") ; The trigger to exit the loop If $X = 0 Then ConsoleWrite(@CRLF & "Exiting the loop" & @CRLF) ExitLoop EndIf ; Show Error Popup window conditionally If $i = 25 Then Run('Notepad.exe') WinWait('Untitled') WinSetTitle('Untitled', '', 'Error Popup') ConsoleWrite('Error Popup ocurred' & @CRLF) EndIf Sleep(100) Next _function() AdlibDisable() Exit Func myadlib() ConsoleWrite("In the Adlib Routine" & @CRLF) If WinExists('Error Popup') Then Sleep(500) WinKill('Error Popup') ConsoleWrite('Found the Error Popup and killed it' & @CRLF) $X = 0 EndIf EndFunc Func _function() ConsoleWrite("I am here, after error occurs" & @CRLF) EndFunc You could also use a 2nd process to do the task of the loop and ProcessClose() it with the Adlib UDF in your main process when error occurs. If you want further help then you are going to need to show some working code that someone can enhance, else members may not to sure exactly what you want to achieve. Jumping out of loops magically without using conditions does not seem reasonable.
everseeker Posted March 31, 2008 Author Posted March 31, 2008 You could also use a 2nd process to do the task of the loop and ProcessClose() it with the Adlib UDF in your main process when error occurs. If you want further help then you are going to need to show some working code that someone can enhance, else members may not to sure exactly what you want to achieve. Jumping out of loops magically without using conditions does not seem reasonable. OK, consider the following change... expandcollapse popup[font="Verdana"]AdlibEnable("MyAdlib") Global $X = 1 ConsoleWrite("Entering the loop" & @CRLF) $i = 1 While $i < 55 ConsoleWrite($i & ", This is a function that modifies critical data, ") $i = $i + 1 ConsoleWrite($i & ", This is another, Different Function, ") $i = $i + 1 ConsoleWrite($i & ", This is yet another, ") $i = $i + 1 ConsoleWrite($i & ", This is yet another, ") $i = $i + 1 ConsoleWrite($i & ", This is yet another, ") $i = $i + 1 ConsoleWrite($i & ", This is yet another, ") $i = $i + 1 ConsoleWrite($i & ", This is yet another, ") $i = $i + 1 ConsoleWrite($i & ", This is yet another, ") $i = $i + 1 ConsoleWrite($i & ", This is yet another, ") $i = $i + 1 ConsoleWrite($i & ", This is yet another, ") $i = $i + 1 ConsoleWrite($i & ", This is yet another, " & @CRLF) $i = $i + 1[/font][font="Verdana"] ; The trigger to exit the loop If $X = 0 Then ConsoleWrite(@CRLF & "Exiting the loop" & @CRLF) ExitLoop EndIf Sleep(100) WEnd[/font][font="Verdana"]_function() AdlibDisable()[/font][font="Verdana"]Exit[/font][font="Verdana"] [font="Verdana"][/font]Func myadlib() ConsoleWrite("In the Adlib Routine" & @CRLF) If $i = 25 Then Sleep(500) ConsoleWrite('Found the Error Popup and killed it' & @CRLF) $X = 0 EndIf[/font][font="Verdana"]EndFunc ;==>myadlib[/font][font="Verdana"] [font="Verdana"][/font]Func _function() ConsoleWrite("I am here, after error occurs" & @CRLF) EndFunc ;==>_function[/font] This makes the Adlib routine look for something that will happen in the middle of a loop... It's a condition that makes all future changes unneeded for the record. If each of the ConsoleWrite($i & ", This is yet another, ") functions are, in fact, Different, applying more transforms to the data... and there are say, 50 of them, Is there a way to avoid adding If $X = 0 Then ConsoleWrite(@CRLF & "Exiting the loop" & @CRLF) ExitLoop EndIf after each step? Currently, the output is: Entering the loop 1, This is a function that modifies critical data, 2, This is another, Different Function, 3, This is yet another, 4, This is yet another, 5, This is yet another, 6, This is yet another, 7, This is yet another, 8, This is yet another, 9, This is yet another, 10, This is yet another, 11, This is yet another, 12, This is a function that modifies critical data, 13, This is another, Different Function, 14, This is yet another, 15, This is yet another, 16, This is yet another, 17, This is yet another, 18, This is yet another, 19, This is yet another, 20, This is yet another, 21, This is yet another, 22, This is yet another, 23, This is a function that modifies critical data, 24, This is another, Different Function, 25, This is yet another, 26, This is yet another, 27, This is yet another, 28, This is yet another, 29, This is yet another, 30, This is yet another, 31, This is yet another, 32, This is yet another, 33, This is yet another, In the Adlib Routine 34, This is a function that modifies critical data, 35, This is another, Different Function, 36, This is yet another, 37, This is yet another, 38, This is yet another, 39, This is yet another, 40, This is yet another, 41, This is yet another, 42, This is yet another, 43, This is yet another, 44, This is yet another, 45, This is a function that modifies critical data, 46, This is another, Different Function, 47, This is yet another, 48, This is yet another, 49, This is yet another, 50, This is yet another, 51, This is yet another, 52, This is yet another, 53, This is yet another, 54, This is yet another, 55, This is yet another, In the Adlib Routine I am here, after error occurs So, the Adlib does not "Catch" the error until i=33... not a big problem... as long as I get out.... But no... The routine goes back, continuing to process all the rest of the records.... Everseeker
MHz Posted March 31, 2008 Posted March 31, 2008 Is there a way to avoid adding If $X = 0 Then ConsoleWrite(@CRLF & "Exiting the loop" & @CRLF) ExitLoop EndIf after each step?You want some immediate action so Adlib is not acceptable for your code. ExitLoop is the keyword that gets you out of a loop so you need to check after each line and use a condition to use ExitLoop. Each operation can be a function that if returns true, then ExitLoop is performed for the immediate jump out of the loop. expandcollapse popupGlobal $i = 1 ConsoleWrite("Entering the loop" & @CRLF) While $i < 55 If _ConsoleWrite($i & ", This is a function that modifies critical data, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is another, Different Function, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 11 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, " & @CRLF) Then ExitLoop $i += 1 Sleep(100) WEnd _function() Exit Func _ConsoleWrite($text) If $i = 25 Then ConsoleWrite(@CRLF & "Exiting the loop" & @CRLF) Return True EndIf ConsoleWrite($text) Return False EndFunc Func _function() ConsoleWrite("I am here, after error occurs" & @CRLF) EndFunc [ Code ] or [ AutoIt ] tags do not accept [ Font ] tags or any other tags within so please do not use them.
everseeker Posted March 31, 2008 Author Posted March 31, 2008 You want some immediate action so Adlib is not acceptable for your code. ExitLoop is the keyword that gets you out of a loop so you need to check after each line and use a condition to use ExitLoop. Each operation can be a function that if returns true, then ExitLoop is performed for the immediate jump out of the loop. expandcollapse popupGlobal $i = 1 ConsoleWrite("Entering the loop" & @CRLF) While $i < 55 If _ConsoleWrite($i & ", This is a function that modifies critical data, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is another, Different Function, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 11 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, ") Then ExitLoop $i += 1 If _ConsoleWrite($i & ", This is yet another, " & @CRLF) Then ExitLoop $i += 1 Sleep(100) WEnd _function() Exit Func _ConsoleWrite($text) If $i = 25 Then ConsoleWrite(@CRLF & "Exiting the loop" & @CRLF) Return True EndIf ConsoleWrite($text) Return False EndFunc Func _function() ConsoleWrite("I am here, after error occurs" & @CRLF) EndFunc [ Code ] or [ AutoIt ] tags do not accept [ Font ] tags or any other tags within so please do not use them. 1. OK, that's 1 more for the "Have to continually test" camp.... that's a heck of a lot of code I'll have to add, just to avoid "branch on error" conventions that 99.8 % of all scripting languages have... 2. Sorry about that... When I copy/pasted my code from another location in the forum, it stuffed the tags in... I didn't notice them... Everseeker
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