Sign in to follow this  
Followers 0
yoinkster

Infinite loops with if ... elseif

5 posts in this topic

Hey guys,

I'm running in an infinite loop and using an if function to catch when a new window is opened. Some of them are specific and I want to handle differently and all the others I just want to handle in some generic way, but the problem is that the window text is generally the same, so I have

While 1
        If WinExists("Application Manager", "Slice database update is complete.") Then
            ; party hard for success
        ElseIf WinExists("Application Manager", "Could not update slice database:  The following error occurred in Express:" & @CRLF & @CRLF & _
                                                "(DBERR01) Database " & StringUpper($slice) & " does not exist. The system cannot find the file specified") Then
            ; handle first way
            
        ElseIf WinExists("Application Manager", "Could not update slice database:  The following error occurred in Express:" & @CRLF & @CRLF & _
                                                "AG.ENTRY does not exist in any attached database.") Then
            ; handle it this way.
        ElseIf WinExists("Application Manager", "Could not update") Then
            ; generic handle    
        EndIf
WEnd

which I'm going to assume won't actually work as this window could open at any time and at any time the script could've executed, say, the first elseif and decided the DBERR doesn't apply and then this window could exist and it would then notice it and do the generic handle instead of the specific handle method since both windows start off with the same text? Is there any clever way of getting round that {if indeed it is even a problem ...}?

Share this post


Link to post
Share on other sites



Hey guys,

I'm running in an infinite loop and using an if function to catch when a new window is opened. Some of them are specific and I want to handle differently and all the others I just want to handle in some generic way, but the problem is that the window text is generally the same, so I have

While 1
        If WinExists("Application Manager", "Slice database update is complete.") Then
        ; party hard for success
        ElseIf WinExists("Application Manager", "Could not update slice database:  The following error occurred in Express:" & @CRLF & @CRLF & _
                                                "(DBERR01) Database " & StringUpper($slice) & " does not exist. The system cannot find the file specified") Then
        ; handle first way
            
        ElseIf WinExists("Application Manager", "Could not update slice database:  The following error occurred in Express:" & @CRLF & @CRLF & _
                                                "AG.ENTRY does not exist in any attached database.") Then
        ; handle it this way.
        ElseIf WinExists("Application Manager", "Could not update") Then
        ; generic handle    
        EndIf
WEnd

which I'm going to assume won't actually work as this window could open at any time and at any time the script could've executed, say, the first elseif and decided the DBERR doesn't apply and then this window could exist and it would then notice it and do the generic handle instead of the specific handle method since both windows start off with the same text? Is there any clever way of getting round that {if indeed it is even a problem ...}?

Use an AdLibEnable function (see help file) to periodically test for the windows. Use only the text that is unique to the conditions your are interested in:
AdlibEnable("_PopupMonitor", 200)

; Rest of the script

Func _PopupMonitor()
    Select
        Case WinExists("Application Manager", "Slice database update is complete.")
        ; party hard for success

        Case WinExists("Application Manager", "(DBERR01) Database " & StringUpper($slice) & " does not exist.")
        ; handle first way

        Case WinExists("Application Manager", "AG.ENTRY does not exist in any attached database.")
        ; handle it this way.

        Case WinExists("Application Manager", "Could not update")
        ; generic handle
    EndSelect
EndFunc  ;==>_PopupMonitor

:P


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

#4 ·  Posted (edited)

Be careful to not add to many WinExist. It can cause processor hunger. You may want to do a winlist and then search for the window you want to check for in an array search.

Good point. Here is an updated function that takes that into account:
Func _PopupMonitor()
    Local $sWinText = ""
    Local $avWinList = WinList("[CLASS:#32770; TITLE:Application Manager]")
    If $avWinList[0][0] Then
        For $n = 1 To $avWinList[0][0]
            $sWinText = WinGetText($avWinList[$n][1])
            Select
                Case StringInStr($sWinText, "Slice database update is complete.")
                ; party hard for success

                Case StringInStr($sWinText, "(DBERR01) Database " & StringUpper($slice) & " does not exist.")
                ; handle first way

                Case StringInStr($sWinText, "AG.ENTRY does not exist in any attached database.")
                ; handle it this way.

                Case StringInStr($sWinText, "Could not update")
                ; generic handle

            EndSelect
        Next
    EndIf
EndFunc ;==>_PopupMonitor

The Window matching pattern include the class #32770, which was just a guess on my part. Replace that with the actual class of the pop ups you see.

:P

Edit: Fixed detection of no windows.

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

Share this post


Link to post
Share on other sites

hey guys, thanks for the advice I have made a few changes to my code and it seems to be doing what I want it to.

Much appreciated.

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