waitwindowopen multiple possibilities

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
liveitupmore
Junior Coder
Posts: 22
Joined: Wed Nov 16, 2005 3:58 am
Location: Gold Coast, Australia

waitwindowopen multiple possibilities

Post by liveitupmore » Sat Aug 22, 2015 5:30 am

After running a program I have a case where 2 or more possible windows could open with different names. How can I wait for the 2 or more possible cases and determine which one has opened, similar to the "case" option in "C". The waitwindowopen works perfect if there is only 1 possible case.

Alistair

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: waitwindowopen multiple possibilities

Post by hagchr » Sat Aug 22, 2015 7:09 am

Hi, you can use RegEx> and look for a pattern that could include options. The following will show a message box when I open one of the files (the first three lines just for showing the file names, no impact on rest of code).

Code: Select all

Let>file1=C:\Users\Christer\Desktop\Temp1.xlsx
Let>file2=C:\Users\Christer\Desktop\Temp2.xlsx
Let>file3=C:\Users\Christer\Desktop\Temp3.xlsx

Let>WIN_REGEX=1
Let>tmp0=Temp1|Temp2|Temp3

//In this case, since the relevant awaited window name all starts
//with Temp it would have been enough to just look for Temp, ie
//Let>tmp0=Temp

WaitWindowOpen>tmp0
Let>WIN_REGEX=0

GetActiveWindow>strTitle,nXPos,nYPos,,

MDL>File %strTitle% was openened!

liveitupmore
Junior Coder
Posts: 22
Joined: Wed Nov 16, 2005 3:58 am
Location: Gold Coast, Australia

Re: waitwindowopen multiple possibilities

Post by liveitupmore » Sat Aug 22, 2015 9:05 am

Hi hagchr,

Many thanks for your prompt reply.

I have never seen the let> function used with "|". How does that work, I can find nothing in the help, is it an OR function.

Alistair

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: waitwindowopen multiple possibilities

Post by hagchr » Sat Aug 22, 2015 9:55 am

Hi, not sure if you have used RegEx before. If not, then it is a flexible way to search for patterns (can be as simple as searching for the string 'Apple' to using much more general (and complicated) patterns).

In this example you are waiting for a window to open by searching for a window name that contains the pattern defined by

Let>tmp0=Temp1|Temp2|Temp3

(ie tmp0 contains a string that is a pattern, ie | is not really related to let>)

In RegEx language | means alternation, ie look for any of the strings Temp1, Temp2, or Temp3. If you had used the pattern Temp then it would have matched all three windows irrespective of the number coming after.

In the base form RegEx is case sensitive, so Temp1 and temp1 is not the same (this can all be adjusted but don't think it will be needed here).

Please come back if unclear.

For more information you can check MS help (RegEx> function) or the many resources on the web, eg:
http://www.regular-expressions.info/quickstart.html

liveitupmore
Junior Coder
Posts: 22
Joined: Wed Nov 16, 2005 3:58 am
Location: Gold Coast, Australia

Re: waitwindowopen multiple possibilities

Post by liveitupmore » Sat Aug 22, 2015 10:26 am

Brilliant, many thanks

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts