everseeker Posted March 27, 2008 Share Posted March 27, 2008 [color="#0000ff"]Global $Killbit = "F" AdlibEnable("Check4Error") global $X=1 ConsoleWrite("Entering the loop" & @CRLF) While $X = 1 ConsoleWrite("1, ") ConsoleWrite("2, ") ConsoleWrite("3, ") ConsoleWrite("4, ") ConsoleWrite("5, ") ConsoleWrite("6, ") ConsoleWrite("7, ") ConsoleWrite("8, ") WEnd[/color][color="#0000ff"]Exit[/color][color="#0000ff"]Func Check4Error() If 1 = 1 Then ConsoleWrite("In the Adlib Routine" & @CRLF) EndIf EndFunc ;==>Check4Error [/color][color="#0000ff"] Output: ... 1, 2, 3, In the Adlib Routine ... 6, 7, 8, In the Adlib Routine ... 3, 4, 5, In the Adlib Routine ... 8, 1, 2, In the Adlib Routine ... 5, 6, 7, In the Adlib Routine ... 2, 3, 4, In the Adlib Routine ... 7, 8, 1, In the Adlib Routine ... 4, 5, 6, In the Adlib Routine ... 1, 2, 3, In the Adlib Routine ... 6, 7, 8, In the Adlib Routine ... 3, 4, 5, In the Adlib Routine ... 8, 1, 2, In the Adlib Routine ... 5, 6, 7, In the Adlib Routine ... 2, 3, 4, In the Adlib Routine ... 7, 8, 1, In the Adlib Routine ... 4, 5, 6, In the Adlib Routine ... 1, 2, 3, In the Adlib Routine ... 6, 7, 8, In the Adlib Routine ... 3, 4, 5, In the Adlib Routine ... 8, 1, 2, In the Adlib Routine ... 5, 6, 7, In the Adlib Routine ... 2, 3, 4, In the Adlib Routine ... 7, 8, 1, In the Adlib Routine ... 4, 5, 6, In the Adlib Routine ... 1, 2, 3, In the Adlib Routine ... 6, 7, 8, In the Adlib Routine ... 3, 4, 5, In the Adlib Routine ... 8, 1, 2, In the Adlib Routine As you can see, the location you are in when an adlib executes (to check for errors mostly) is variable. Given that, how do you "stop" the execution of commands in the loop above when an error has occured? ... not by setting $X to 0 in the Adlib function... that would still execute whatever commands remain in the loop (Unless you add, TO EVERY COMMAND IN YOUR PROGRAM, "If $X=1 then" then the command, which would be a nightmare) Everseeker Link to comment Share on other sites More sharing options...
Squirrely1 Posted March 27, 2008 Share Posted March 27, 2008 This code works properly on my machine, a Compaq built in 2002, running XP - AdlibEnable does stop execution of the current statement and runs the function as normal: AdlibEnable("Check4Error") Global $X = 1 ConsoleWrite("Entering the loop" & @CRLF) While $X = 1 ConsoleWrite("1, ") ConsoleWrite("2, ") ConsoleWrite("3, ") ConsoleWrite("4, ") ConsoleWrite("5, ") ConsoleWrite("6, ") ConsoleWrite("7, ") ConsoleWrite("8, ") WEnd Func Check4Error() ConsoleWrite("In the Adlib Routine" & @CRLF) EndFunc ;==>Check4Error Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
everseeker Posted March 27, 2008 Author Share Posted March 27, 2008 This code works properly on my machine, a Compaq built in 2002, running XP - AdlibEnable does stop execution of the current statement and runs the function as normal:my point is that the "current statement" is "Whatever statement the application happens to be at 250ms since the last time the subroutine ran"Since THAT is variable, you can't plan for it Everseeker Link to comment Share on other sites More sharing options...
everseeker Posted March 27, 2008 Author Share Posted March 27, 2008 (edited) my point is that the "current statement" is "Whatever statement the application happens to be at 250ms since the last time the subroutine ran"Since THAT is variable, you can't plan for itHow would you code the following: If a popup error message appears while running a loop, telling me I have bad data, do not continue to process this bad data... get more(loop)Without wrapping each and every line of code in a conditional likeData still OK?... do thisData still OK?... do thisData still OK?... do thisData still OK?... do thisCuz that looks silly Edited March 27, 2008 by everseeker Everseeker Link to comment Share on other sites More sharing options...
Squirrely1 Posted March 27, 2008 Share Posted March 27, 2008 (edited) Maybe you just need a new kind of timer - Adlib's are recommended sometimes just because they don't use as much of the PC's resources. I can think of about four different ways of timing an operation including GaryFrost's new timer functions you can find on the forums - maybe post some code if you want help. Edited March 27, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
everseeker Posted March 27, 2008 Author Share Posted March 27, 2008 (edited) Maybe you just need a new kind of timer - Adlib's are recommended sometimes just because they don't use as much of the PC's resources. I can think of about four different ways of timing an operation including GaryFrost's new timer functions you can find on the forums - maybe post some code if you want help. 1. Timer? I do not need a timer. in my previous post... I state in plain text what I am attempting to do How would you code the following: If a popup error message appears while running a loop, telling me I have bad data, do not continue to process this bad data... get more(loop) Without wrapping each and every line of code in a conditional like Data still OK?... do this Data still OK?... do this Data still OK?... do this Data still OK?... do this Cuz that looks silly 2. My code? I already posted it in response to your accusation that I was trying to hack the world bank but, here it is again: The "Loop" I am having an issue with runs from 164 to 399 You can see my current "solution"... AdlibEnable("myadlib") If $AbortRow = "False" Then ControlClick("Rate Calculator", "", "[TEXT:Get A Quote]") If $AbortRow = "False" Then ConsoleWrite("Move to Choose Plans page." & @CRLF) Sleep(750) Edited March 27, 2008 by everseeker Everseeker Link to comment Share on other sites More sharing options...
Squirrely1 Posted March 27, 2008 Share Posted March 27, 2008 (edited) CertificationThis is to certify that everseeker is as far as has been determined by squirrely authority, not currently engaged in hacking the World Bank, likely. Edited March 27, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
everseeker Posted March 27, 2008 Author Share Posted March 27, 2008 CertificationThis is to certify that everseeker is as far as has been determined by squirrely authority, not currently engaged in hacking the World Bank, likely.I thank thee kindlyNow, have a solution to my problem? Everseeker Link to comment Share on other sites More sharing options...
Squirrely1 Posted March 27, 2008 Share Posted March 27, 2008 No, I'm just wondering if it is true - "Stove pipe won't shut." Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
FreeFry Posted March 27, 2008 Share Posted March 27, 2008 Even though I managed to recover the code in the code box you totally bombared, it still runs as predicted. What I don't understand by your first post is what you're trying to achieve.. my point is that the "current statement" is "Whatever statement the application happens to be at 250ms since the last time the subroutine ran" Since THAT is variable, you can't plan for it If you want to "time" the adlib function or w/e you Squirrely1 provided a viable solution a few posts back. AdlibEnable("myadlib") If $AbortRow = "False" Then ControlClick("Rate Calculator", "", "[TEXT:Get A Quote]") If $AbortRow = "False" Then ConsoleWrite("Move to Choose Plans page." & @CRLF) Sleep(750) If this is really what you're asking, then you can simply fix it by doing If $AbortRow <> "False" Then ContinueLoop; Or Exitloop, your code, and I haven't bothered looking at it. Link to comment Share on other sites More sharing options...
everseeker Posted March 28, 2008 Author Share Posted March 28, 2008 Even though I managed to recover the code in the code box you totally bombared, it still runs as predicted. What I don't understand by your first post is what you're trying to achieve.. If you want to "time" the adlib function or w/e you Squirrely1 provided a viable solution a few posts back. If this is really what you're asking, then you can simply fix it by doing If $AbortRow <> "False" Then ContinueLoop; Or Exitloop, your code, and I haven't bothered looking at it. consider the following AdlibEnable("MyAdlib") global $X=1 ConsoleWrite("Entering the loop" & @CRLF) While $X = 1 ConsoleWrite("1, ") ConsoleWrite("2, ") ConsoleWrite("3, ") ConsoleWrite("4, ") ConsoleWrite("5, ") ConsoleWrite("6, ") ConsoleWrite("7, ") ConsoleWrite("8, ") WEnd ConsoleWrite("I am here, after error occurs ") Exit Func myadlib() If WinGetHandle("") <> $handle And WinGetTitle("") = "Error Popup" Then ConsoleWrite("In the Adlib Routine" & @CRLF) WinKill("Error Popup", "") $x=0 EndIf EndFunc ;==>myadlib where would you place the Exitloop() to make sure that NO more lines execute after the error popup is handled? Everseeker Link to comment Share on other sites More sharing options...
FreeFry Posted March 28, 2008 Share Posted March 28, 2008 You could put it at the beginning of your While loop, but I don't really see the need for it really.. You could just increase the "poll" rate of he AdlibEnable function with the second parameter, and maybe shorten down your adlib function(so it doesn't do that much processing each time it's executed) by doing If Not WinExist("Error Popup") Then Return inside it... Other than that I believe the only way is to have it check the state of $x before executing anything in your While loop. This is the problem I believe you have to face with all multi-tasking code that is made to cooperate(which this basically is).. Link to comment Share on other sites More sharing options...
everseeker Posted March 28, 2008 Author Share Posted March 28, 2008 (edited) You could put it at the beginning of your While loop, but I don't really see the need for it really.. You could just increase the "poll" rate of he AdlibEnable function with the second parameter, and maybe shorten down your adlib function(so it doesn't do that much processing each time it's executed) by doing If Not WinExist("Error Popup") Then Return inside it... Other than that I believe the only way is to have it check the state of $x before executing anything in your While loop. This is the problem I believe you have to face with all multi-tasking code that is made to cooperate(which this basically is).. What would be BEST would be for the authors of Autoit3 concede that there are SOME cases where branching is a good thing. possibly something like: [font="Verdana"]AdlibEnable("MyAdlib") global $X=1 ConsoleWrite("Entering the loop" & @CRLF) While $X = 1 ConsoleWrite("1, ") ConsoleWrite("2, ") ConsoleWrite("3, ") ConsoleWrite("4, ") ConsoleWrite("5, ") ConsoleWrite("6, ") ConsoleWrite("7, ") ConsoleWrite("8, ") WEnd ::Label1 ConsoleWrite("I am here, after error occurs ") Exit Func myadlib() If WinGetHandle("") <> $handle And WinGetTitle("") = "Error Popup" Then ConsoleWrite("In the Adlib Routine" & @CRLF) WinKill("Error Popup", "") $x=0 EndIf Return ::Label1 EndFunc ;==>myadlib[/font] where the return simply re-directs the exit point of the function. From where it came from (which you cannot control) to a defined location. Edited March 28, 2008 by everseeker Everseeker Link to comment Share on other sites More sharing options...
FreeFry Posted March 28, 2008 Share Posted March 28, 2008 Perhaps, I've never run into any problems the way stuff works now though.. That's like the Goto command in AutoIt v2, which they scrapped cus it was a "debugging nightmare" if I remember right.. Link to comment Share on other sites More sharing options...
Squirrely1 Posted March 28, 2008 Share Posted March 28, 2008 (edited) "GoTo" not required in your example; this does the same thing: AdlibEnable("MyAdlib") Global $X = 1 ConsoleWrite("Entering the loop" & @CRLF) $GoTo_Label1 = 0 While $X = 1 For $i = 1 To 8 If Not $GoTo_Label1 Then ConsoleWrite($i & ", ") Else ExitLoop EndIf Next WEnd ;Label1 ConsoleWrite("I am here, after error occurs ") Exit Func myadlib() If WinGetHandle("") <> $handle And WinGetTitle("") = "Error Popup" Then ConsoleWrite("In the Adlib Routine" & @CRLF) WinKill("Error Popup", "") $X = 0 EndIf $GoTo_Label1 = 1 Return $GoTo_Label1 EndFunc ;==>myadlib If you continue to complain about this issue, someone, but not me, would end up referring you, everseeker, in an unqualified way to verse five of the Canon of Valik. Edited March 28, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
everseeker Posted March 28, 2008 Author Share Posted March 28, 2008 (edited) "GoTo" not required in your example; this does the same thing: AdlibEnable("MyAdlib") Global $X = 1 ConsoleWrite("Entering the loop" & @CRLF) $GoTo_Label1 = 0 While $X = 1 For $i = 1 To 8 If Not $GoTo_Label1 Then ConsoleWrite($i & ", ") Else ExitLoop EndIf Next WEnd ;Label1 ConsoleWrite("I am here, after error occurs ") Exit Func myadlib() If WinGetHandle("") <> $handle And WinGetTitle("") = "Error Popup" Then ConsoleWrite("In the Adlib Routine" & @CRLF) WinKill("Error Popup", "") $X = 0 EndIf $GoTo_Label1 = 1 Return $GoTo_Label1 EndFunc;==>myadlib If you continue to complain about this issue, someone, but not me, would end up referring you, everseeker, in an unqualified way to verse five of the Canon of Valik. Since I KNOW that you are fully aware that my example was intended to represent a large program in a smll space, representing different code (if you opened my icky code and took a look, you'd see what I mean) with simple consolewrites, I will assume that your proposed suggestion was intended to be a joke. Ha ha and again... Ha --- Edit: If you were serious, may I refer you to #4 and 8 of your Canon of Valik. Edited March 28, 2008 by everseeker Everseeker Link to comment Share on other sites More sharing options...
everseeker Posted March 28, 2008 Author Share Posted March 28, 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 loop Everseeker Link to comment Share on other sites More sharing options...
ResNullius Posted March 28, 2008 Share Posted March 28, 2008 (edited) 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 loopThanks a lot everseeker! This is just the kind of problem that keeps me up at night. I don't KNOW that there is a simple solution. As you know, the nature of a while loop is to iterate thru and execute all the statements for each pass of the loop, with the While condition being checked before the start of the next trip thru the loop. Conditional IF checking of the externally Adlib set variable at each step of the loop appears to be the only way to guarantee an exit at the appropriate location (if/until the Return/Jump to a specific point as you proposed is implemented; don't hold your breath!). I tackled this last night (and today in every spare moment) from every angle I can think of but no luck. I'm no coding master by any means but I do tend to try everything that doesn't work before surrendering I even checked out PsaltyDS's post in this thread: Breaking out of loop with a hotkey because Toady's original problem sounded very much the same. But it's not really Edited March 28, 2008 by ResNullius Link to comment Share on other sites More sharing options...
ResNullius Posted March 29, 2008 Share 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? Link to comment Share on other sites More sharing options...
Squirrely1 Posted March 29, 2008 Share Posted March 29, 2008 (edited) Is there any way to exit a loop as soon as the program sees that an external issue is raisedwithout 1 running all the other code in the loop, exiting at the end2. including a if badcondition then Exitloop before each line in the loopor3. includig a if not badcondition then ...command... endif around each condition in the loopGUIRegisterMsg is used to interrupt script execution - but it requires knowing the windows message. Then you could use switches like I used. But you shouldn't be so concerned about having to use a few extra lines of code just because there is no GoTo function. Today's computers are pretty quick and have lots of RAM.No - don't refer me to any of the verses, those are only for use by me to help reduce typing. Edited March 29, 2008 by Squirrely1 Das Häschen benutzt Radar 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