Jump to content

Misbehaving Do...Until loop


 Share

Recommended Posts

G'day everyone

I'm using Do...Until in a loop and I want the script to exit that loop when the time is ripe. However, the loop doesn't want to stop looping. Here's my code (the entire script is attached -- the additional programs in it are ResHack and XnView):

$a = 0

Do

;Some stuff here

If WinExists ("Dialog", "") Then
; Do some XYZ stuff
Else
$a = 1
EndIf

Until $a = 1

My reasoning is that once $a is 1, the Do loop should stop... right? But it doesn't. It continues even though the window "Dialog" no longer exists. Any ideas?

Thanks

Samuel

screencapscript2.zip

Link to comment
Share on other sites

  • Moderators

You could always do it with a while/wend loop a bit different:

While 1
    If WinExists ("Dialog", "") Then
        WinActivate ("Dialog", "")
        WinWaitActive ("Dialog", "")
        Send ("!d")
        Sleep (100)
        $a = 1
    EndIf
    If Not WinExists('Dialog') And $a = 1 Then ExitLoop
WEnd

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

He had alot more stuff in that loop is why I suggested what I did.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

G'day everyone

I'm using Do...Until in a loop and I want the script to exit that loop when the time is ripe. However, the loop doesn't want to stop looping. Here's my code (the entire script is attached -- the additional programs in it are ResHack and XnView):

$a = 0

Do

;Some stuff here

If WinExists ("Dialog", "") Then
; Do some XYZ stuff
Else
$a = 1
EndIf

Until $a = 1

My reasoning is that once $a is 1, the Do loop should stop... right? But it doesn't. It continues even though the window "Dialog" no longer exists. Any ideas?

Thanks

Samuel

I think SmOke_N was closest, but the logic is changed my moving the $a=1. I would have dropped it completely and put:

While 1
    
    ; Other stuff from the original Do loop...

    If WinExists("Dialog", "") Then
        WinActivate("Dialog", "")
        WinWaitActive("Dialog", "")
        Send ("!d")
        Sleep (100)
    Else
        ExitLoop
    EndIf
WEnd

Allows you to check that the script gets to that code at all.

:whistle:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...