Jump to content

adlib not predictable....


Recommended Posts

[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

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

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

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

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

Edited by everseeker

Everseeker

Link to comment
Share on other sites

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 by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

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 by everseeker

Everseeker

Link to comment
Share on other sites

Certification

This 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 by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

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

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

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

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 by everseeker

Everseeker

Link to comment
Share on other sites

"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 by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

"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 by everseeker

Everseeker

Link to comment
Share on other sites

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

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

Thanks 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 by ResNullius
Link to comment
Share on other sites

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

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

GUIRegisterMsg 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 by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...