I'm trying to make my script discover if a certain window appear. An example of my code on notepad.exe is below, and the line in red should describe want I want. I know this doesn't work, and I think that the event Whenever might do the trick. I tried different ways, but i was not able to make the Whenever statement work. I used Event->Window, attached the event to the window and tried with Active, Exists, Focus and other, but I couldn't make it work.
The .exists property is an instant check. So 2 things could happen.
1) It checks for the window before the window has had time to display.
2) The window did not display.
The problem being you may not be sure which actually occurred.
I tend to have a function which allows for the window to appear in a particular time i.e.
Function WaitForWindow(iTime As Integer, strAttch As String) As Boolean
Dim TimeToWait As Date
TimeToWait = Now + (iTime / 86400)
If Window(strattach, tpAttachNoWait).Exists = True Then
WaitForWindow = True
Loop Until Now > TimeToWait
WaitForWindow = False
This will check for up to the specified time (in seconds) for the window to display.
Oh and I really do not like whenever's as they add an overhead to the script which can slow things down. I have rarely seen an application that behaves so erratically - usually things happen when a button is clicked, enter is hit etc. (though I am now waiting to proven wrong!)
The main problem with
"If DotNETForm("Scenario Editor DotNETForm").Exists Then"
seems to be that when the window doesn't appear, the script stops at this point. Seems to me that the code of line fails rather than returning False. It should have returned false as the window doesn't exist and continued after the "End If"
Here is my experience with working with whenever events:
1. Due to how TP does the whenever events [polling for the event], you need to place whenever statement at the top most part of the sub main. I do it right after sub main statement.
2. Change your window events to screen events as window events are not stable [as I've been told my compuware several times. There are certain conditions as to why you use the window events, but I didn't quite get it [4pm on a Friday]. Besides, the tech was just reading the help to me that I can just do myself.