ChiSao Posted March 8, 2010 Posted March 8, 2010 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
El_Pablo Posted March 8, 2010 Posted March 8, 2010 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.
efen Posted March 8, 2010 Posted March 8, 2010 Commit records If[ValueCount(windowNames(Get(WindowName)))>1] Close window [current window] End if
David Jondreau Posted March 8, 2010 Posted March 8, 2010 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 )
David Jondreau Posted March 9, 2010 Posted March 9, 2010 I should have commented that the testWindow = Get(windowName) should really be testWindow = "The Name of Window". As written, the result will always be true.
El_Pablo Posted March 10, 2010 Posted March 10, 2010 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 :.
Newbies dcol Posted August 14, 2010 Newbies Posted August 14, 2010 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.
comment Posted August 14, 2010 Posted August 14, 2010 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 dcol Posted August 16, 2010 Newbies Posted August 16, 2010 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!
Vaughan Posted August 16, 2010 Posted August 16, 2010 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" ) )
Jed69 Posted March 14, 2011 Posted March 14, 2011 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
Vaughan Posted March 14, 2011 Posted March 14, 2011 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
Jed69 Posted March 14, 2011 Posted March 14, 2011 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
comment Posted March 14, 2011 Posted March 14, 2011 Try: If [ Position ( ¶ & WindowNames ; ¶ & "Event Detail" ; 1 ; 1 ) ] ...
Jed69 Posted March 17, 2011 Posted March 17, 2011 Brilliant Comment, just worked out how this works, Just what I need. Thank you
Rich S Posted July 21, 2013 Posted July 21, 2013 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?
LaRetta Posted July 22, 2013 Posted July 22, 2013 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now