Jump to content

WinWait Active - Set Timeout and Error in one location


Recommended Posts

Hello All,

I have written a fairly lengthy script that includes quite a few WinWaitActive commands. I had not added a timeout to any of the commands (which wouldn't be too big a deal to have to go back and do), but I am wondering if there is a way to have the script goto an onerror function (gathers some debug info before exiting) after the WinWait Timeout has been reached. I am looking for a way to NOT have to do the following for each instance:

$Result = WinWaitActive("WINDOW TITLE", "WINDOW TEXT ")

If ($Result = 0) Then

_FileWriteLog($TmpFolder & "\Install.log", "ERROR: TIMEOUT: Waiting For Window FAILED")

onerror()

Exit

Else

_FileWriteLog($TmpFolder & "\Install.log", "Window Found")

EndIf

Thanks in Advance,

-Chris

Link to comment
Share on other sites

Hello All,

I have written a fairly lengthy script that includes quite a few WinWaitActive commands. I had not added a timeout to any of the commands (which wouldn't be too big a deal to have to go back and do), but I am wondering if there is a way to have the script goto an onerror function (gathers some debug info before exiting) after the WinWait Timeout has been reached. I am looking for a way to NOT have to do the following for each instance:

$Result = WinWaitActive("WINDOW TITLE", "WINDOW TEXT ")

If ($Result = 0) Then

_FileWriteLog($TmpFolder & "\Install.log", "ERROR: TIMEOUT: Waiting For Window FAILED")

onerror()

Exit

Else

_FileWriteLog($TmpFolder & "\Install.log", "Window Found")

EndIf

Thanks in Advance,

-Chris

Just turn it into a UDF and use that in place of WinWaitActive():
_WinExpected("WINDOW TITLE", "WINDOW TEXT ", 120); Wait max 2min.

Func _WinExpected($sWinTitle, $sWinText, $iTimeout = 30)
    ; Default timeout = 30sec
    ; $TmpFolder must be globally declared
    Local $Result = WinWaitActive($sWinTitle, $sWinText, $iTimeout)
    If ($Result = 0) Then
        _FileWriteLog($TmpFolder & "\Install.log", "ERROR: TIMEOUT: Waiting For Window FAILED: " & $sWinTitle & "; " & $sWinText)
        onerror()
        Exit
    Else
        _FileWriteLog($TmpFolder & "\Install.log", "Window found active: " & $sWinTitle & "; " & $sWinText)
        Return 1
    EndIf
EndFunc ;==>_WinExpected

:D

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...