5 Replies Latest reply on Oct 19, 2014 10:09 AM by FentonJones

    Close other windows

    rlamberts

      Title

      Close other windows

      Post

      I have made a "coffee break" screen that allows my users to log off but still keep the program running.  I am trying to close all other windows (in case there is more than one window open).  How do I close all windows but the current "Coffee Break" window?  It sounds easy, but I can't figure out how to do it.

        • 1. Re: Close other windows
          FentonJones

          The current window is at the top. We don't want to close it, but all the others, so we leave it out of the list.

          $wins means: windows (list); $win means: window (line)

          Script:

          Freeze Window

          Set Variable [ $wins; Value:RightValues ( WindowNames; ValueCount (WindowNames) - 1 )
          Loop
              Set Variable [ $win; Value:Left ( LeftValues ($wins; 1); Length ( LeftValues ($wins; 1)) - 1) ]
              Set Variable [ $wins; Value:RightValues ( $wins; ValueCount ($wins) - 1) ] 
              Close Window [ Name: $win ] 
              Exit Loop If [ ValueCount ( WindowNames ) = 1 ]
          End Loop

          • 2. Re: Close other windows
            rlamberts

            Excellent.  Thank you.

            • 3. Re: Close other windows
              jabs.far

              Doesn't this bring the risk of leaving the "wrong window" open, in case "Coffee Break" is not the bottom most window ?! I'd try to specifically protect that from closing by excluding the WindowName "Coffee Break" from the Variable ...

              Like for instance in this :

              Set Variable [ $wins; Value:

              Case (

              PatternCount ( WindowNames ; ("Coffee Break" & ¶ ) ) ; Substitute ( WindowNames ; "Coffee Break" & ¶ ; "" ) ;

              PatternCount ( WindowNames ; "Coffee Break" ) ; Substitute ( WindowNames ; "Coffee Break" ; "" )

              )  

               

              Does this make any sense to you ?!

              Jan

              • 4. Re: Close other windows
                rlamberts

                Yes, that does make sense, I actually thought of that (once I discovered the WindowNames function).  In this case the "Coffee Break" window will always be the last one opened because opening it is the trigger to close all of the others.  I think this puts it at the bottom of the list. It has worked so far, but doing a loop based on names would work.

                • 5. Re: Close other windows
                  FentonJones

                  Oops. I made a mistake in what I "said". The current window is at the "top" (not the "bottom"). I should have known this because of the RightValues. The script was writen years ago. Here is another "newer, simpler" version:

                  Freeze Window 
                  Set Variable [ $wins; Value:RightValues ( WindowNames; ValueCount (WindowNames) - 1 )
                  Set Variable [ $wins_cnt; Value:ValueCount ( $wins ) ]
                  Loop
                      Set Variable [ $num; Value:$num + 1 ]
                      Exit Loop If [ $num > $wins_cnt ]
                      Set Variable [ $win; Value:GetValue ( $wins ; $num ) ]
                      Close Window [ Name: $win ]
                  End Loop