Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 4146 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi,

I have a multi Window Solution and qould like to ask if its possible to check if a Window is open or not.

Because I would like to avoid the same window more than once at a time.

thx

ChiSao

Posted

Function "WindowsName" returns a list with the name of all windows.

Do a patterncount with the window you want to check to see if it exists.

Eg :)

WindowNames return

Window_a

Window_a0

Window_B

If you check for "Window_a" it will return 2.

For better result check for a custom function in fmfunctions.com or briandunning.com that will allow to check the exact presence of an element name in the list.

Posted

No need for a custom function.

Let([

//Grab window names

windows = WindowNames(Get(FileName));

//add pilcrow as delimiter

windows = ¶ & windows & ¶;

//Grab test window name

thisWindow = Get(WindowName);

//add delimiter

thisWindow = ¶ & thisWindow & ¶;

//test

test = PatternCount(windows;thisWindow)

];

test

)

Posted

In fact, the calculation you wrote is what my CF would look alike.

It is always useful to have a custom function that checks if an element is in a list.

It's even easier with FM11 since we can now import CF :.

  • 5 months later...
  • Newbies
Posted

Found a very quick and easy way to test whether a window exists:

If [ Position ( WindowNames; "{window name}¶" ; 1 ; 1 ) > 0 ]

Replace {window name} with the name of the window you are looking for. Since the WindowNames function returns a list of names followed by carriage returns, the ¶ symbol is necessary to distinguish between similarly named windoes. For example, if you performed a "new window" command while the window you are looking for (say "Contacts") is open, FM will create a new window with the same name followed by " - 2" or " - 3" etc (e.g. Contacts -2, Contacts -3). With the ¶ FM will always refer to only the original window.

Posted

If [ Position ( WindowNames; "{window name}¶" ; 1 ; 1 ) > 0 ]

This will fail in two cases: (a) when the window you are looking for is the last one on the list (no trailing ¶), and (: when an existing window has a name that ends with with searched name.

It's best to use the FilterValues() function for this.

  • Newbies
Posted

Right you are!

In my case the window I am looking for is named "Contacts," so I entered the following and it works better than my prior post:

If [FilterValues ( WindowNames ; "Contacts" ) ≠ ""]

I love one-line solutions.

Thanks!

Posted

Don't use ≠ "" this never has been a good practice and I believe that it now breaks in some circumstances.

Use instead the IsEmpty() function - that's what it's for. Or in this eaxmple, Not Isempty.

Not Isempty( FilterValues ( WindowNames ; "Contacts" ) )

  • 6 months later...
Posted

This is brilliant works great for me, however I would like to make it so that if the window starts with a name in this case Event Detail it will work.

eg Not Isempty( FilterValues ( WindowNames ; "Event Deail" ) )

Thought about using a left function but can not get my head around where to implement it.

Can anyone help.

John

Posted

There is an alternative method to determine whether a window is open: select the window by name and see whether there was an error.


Set Error Capture [on]

Select Window [ windowname ]

Set variable [ $error ; Get( lastError ) ]

Set Error Capture [off]

If [ $error = 0 ]

#window with that name exists and is selected

End If

Posted

Hi Vaughan, Thank you for the code, looks great and I think it would work well for me. However I am still not sure how to get it to return when I only want it to check the start of the Window name.

For example, the window´s name is "Event Detail - and the date of the event" So I want it to select any window that starts Event Detail regardless of the other information that follows it.

Sorry if i am missing something obvious.

many thanks

John

  • 2 years later...
Posted

Try:

 

If [ Position ( ¶ & WindowNames ; ¶ & "Event Detail" ; 1 ; 1 ) ]
...

 

Sorry for being dense, but where would that line of code go in the script? Also, say I have more than one window open beginning with the name, WEBSITE; how would I close all those windows in one shot?

Posted

Your script would look something like this, considering that you use a global text field called Phrase to hold the portion of the window name you are looking for:

 

Script Name:  Close all phrase windows

 

Set Variable [ $windows ; Value: WindowNames

Loop

Exit Loop If [ Let ( $count = $count + 1 ; $count > ValueCount ( $windows ) ) // we're counting through all the windows ]
If [ LeftWords ( GetValue ( $windows ; $count ) ; 1 ) = tableName::Phrase  // or replace blu field reference to Phrase with text as "website" 
 ]

Close Window [ Name: GetValue ( $windows ; $count ) ; Current file ]

End If

#

End Loop 

 

ADDED:  I thought it faster and best to set a variable with the window names instead of recalculating WindowNames again each time but ... if Users continually are opening a WEBSITE window then some might be opened while the script is running (although unlikely).  However small, the possibility exists so you may wish to loop the WindowNames instead.

This topic is 4146 days old. Please don't post here. Open a new topic instead.

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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.