Sign in to follow this  
Followers 0
cfay

WinWait Active - Set Timeout and Error in one location

3 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Very Clever :D Thank you that is a great idea, I will try that.

Thanks again,

-Chris

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