Sign in to follow this  
Followers 0
anandnz

Help in review; Loops and break

3 posts in this topic

#1 ·  Posted (edited)

Hi Gurus,

Thank you for help. I am not able to find the old thread posted after forum got live again.

I have this piece of code, it was running indefinetly for ever doing what it is intended to do to close the popups, however. when i put some conditions, it breaks out from the first loop, any advice alternatives is highly appreciated as always.. I have 3-4 steps before i complete my task. Please give your opinion on the best way to do this .. as my loop has several iterations to run third party software, which cannot be controlled, all i control is the pop ups.

Here is the code.

#include <WinAPI.au3>
#include <File.au3>
Opt('WinTitleMatchMode', 2)
Local $ret =1
while 1
    ;AdlibRegister("_handlepop", 1000)
    sleep(3000)
    _Main()
WEnd
Func _Main()
    Local $aWindows, $i, $what; $text
    $aWindows = _WinAPI_EnumWindows()
    Local $OutStg
    local $Alldone = 0
    For $i = 1 To $aWindows[0][0]
        $Alldone = 0
        Local $Wclass = $aWindows[$i][1]
        Local $Wtitle = WinGetTitle($aWindows[$i][0])
        if $Wclass = "#32770" And $Wtitle = "Error" Then
            $Alldone = 1
            $OutStg = $Wtitle &   $Wclass
            ControlGetFocus("Error","Failed to load defin")
            ConsoleWrite(" got a error ......" & @CRLF)
            ;_handlepop($Wtitle,$Wtext)
            ;_handlepop()
            while 1
                $Alldone = _handleErrorMsg()
                If $Alldone = "All close" Then  ; THIS IS ADDED TO COMPARE ONLY THEN QUIT 
                    Exit
                EndIf
            WEnd
            ConsoleWrite("The window details are " & $OutStg & @CRLF)
        else
           continueloop
        ;_FileWriteLog($logpath, $OutStg)
        ;ConsoleWrite("Item " & $i & " of " & $aWindows[0][0], $text)
        EndIf
    Next
    ;Return $Alldone
EndFunc   ;==>_Main
;Func _handlepop($title, $string)

#comments-start
#comments-end
Func _handleErrorMsg()
    Local $loadfail = 0
    Local $WordClose = 0
    ControlGetFocus("Error","Failed to load defin")
    if WinExists("Error","Failed to load defin") Then
        ConsoleWrite(" found a window " & @CRLF)
        controlsend("","","","{ENTER}")
        $loadfail = 1
    Else
        ControlFocus("Error","","")
        if WinExists("Error") Then
            controlsend("","","","{ENTER}")
            ConsoleWrite("word close " & @CRLF)
            $WordClose = 1
        EndIf
    EndIf
    if ($loadfail =1) And ($WordClose = 1) Then  ; THESE CONDITIONS WERE ADDED TO ENSURE IT SATISFIES BOTH THE LOOPS, AS 1. POPUP IS ERROR AND 2. IS THE WINDOW CLOSURE ... ( CONSIDERED THIS TO SHORTEN TEST)
        ConsoleWrite(" both parameters met " & $loadfail  & $WordClose & @CRLF)
        Return "All close"
    EndIf

EndFunc

The end result is it only executes the first pop up... Any help is appreciated.

This is the output from this ..

got a error ......

found a window

+>14:42:27 AutoIT3.exe ended.rc:0 -- Exited here ..

But i want to go on until if ($loadfail =1) And ($WordClose = 1).

Edited by anandnz

Share this post


Link to post
Share on other sites



You have to be careful with things like this:

If $Alldone = "All close" Then

The "=" operator is a numeric compare by default. If you have $Alldone = 0, then that compare is true because "All close" converted as with Number() is also 0.

You might try this instead:

If $Alldone == "All close" Then

Or this:

If String($Alldone) = "All close" Then

:)


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

Share this post


Link to post
Share on other sites

Thank you a lot PsaltyDs. I am doing same mistake.. Varian has warned me earlier as well. Thank you very much. I will try this.

Share this post


Link to post
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
Sign in to follow this  
Followers 0