14 Replies Latest reply on Feb 11, 2015 11:46 AM by disabled_jackrodgers

    Close Script

      Hi Everyone,

       

      I know this is easy, but I cant make it work. Please pardon my newbieness.

      Can you help me with my script below in closing my file.

      my problem is if I click cancel my file is closing.

       

      Show Custom Dialog [Logout" ; Close the application or relogin as a different user?"]

      If [Get (LastMessageChoice) = 2]

      Re-login[]

      Perform Script ["Startup"]

      Exit Script[]

      Else If [Get (lastMessageChoice) = 3]

      Exit Script []

      Else

      Close File [Current File]

      End If

       

      Thank you.

        • 1. Re: Close Script
          mtwalker

          The buttons numbers are ordered Right to Left so in your case the Cancel button should be the far left button. Is that how you have it set up?

          If not st the last Else If to Get (lastMessageChoice) = 1

          • 2. Re: Close Script
            erolst

            rosalie wrote:

            my problem is if I click cancel my file is closing.

            Let me suggest to add a Comment[] step to a Show Custom Dialog[] step to simply list the button options, in the same order – default/1, 2, 3  – they are queried in Get ( LastMessageChoice ); makes debugging easier. Check that the labelling & order of the buttons confirms to your logic.

             

            Since Cancel doesn't do anything anyway, you could write

             

            Show Custom Dialog [ "Logout?" ; "Do you want to close the application, or re-login as a different user?" ]

            # 1 = Exit, 2 = Re-login, 3 = Cancel

            If [ Get ( LastMessageChoice) = 1 ]

              Close File [ Current File ]

            Else If [ Get ( LastMessageChoice ) = 2 ]

              Re-login[]

              Perform Script ["Startup"] 

            End If

            • 3. Re: Close Script
              nicolai

              I second @Todd answer - it looks like a confusion with button order.

               

              The default setup is Cancel button's lastMessageChoice=2 and OK = 1. So this in theory should not close the file.

               

              Unless the OK and Cancel buttons were swapped around.

              • 4. Re: Close Script
                hbrendel

                If this script is invoked by 'OnLastWindowClose' script trigger, then you should add a script result of 'False' (0).

                 

                So, Exit Script [0], instead of Exit Script []

                 

                This way you prevent the action that triggered the script.

                • 5. Re: Close Script

                  Hi All,

                   

                  Im confuse, Tried the calculation suggested by Erolst, still Im getting the same problem.

                  • 6. Re: Close Script
                    wimdecorte

                    We don't know how you've set up your buttons... is button #1 cancel?

                     

                    Right to Left: what are your buttons named?

                    • 7. Re: Close Script
                      Mike Duncan

                      hbrendel is right, if the event to close the windows has already been triggered, the you must exit the script with a condition that evaluates as false. That should do it.


                      Mike

                      • 8. Re: Close Script

                        My Buttons from left to right are

                         

                        Button 3 = Cancel

                        Button 2 = Relogin

                        Default Button  = Close

                         

                        My new script now is

                         

                        If [ Get ( LastMessageChoice) = 1 ]

                          Close File [ Current File ]

                        Else If [ Get ( LastMessageChoice ) = 2 ]

                          Re-login[]

                          Perform Script ["Startup"]

                        Else If [ Get ( LastMessageChoice ) = 3 ]

                        Exit Script [Result:0]

                        End If

                         

                        When I click my Relogin Button my file is closing.

                        • 9. Re: Close Script
                          wimdecorte

                          You also have to exit[0] on the Relogin to cancel the close event

                          • 10. Re: Close Script

                            I add another script Exit Script [Result:0] after Perform Script ["Startup"]

                            As Wim suggested, now its working.

                             

                            Thank you for all the suggestions.

                            • 11. Re: Close Script
                              DavidJondreau

                              You also should put some error trapping in there. If the re-login fails, what should happen?

                              • 12. Re: Close Script

                                Hi David,

                                 

                                Like set error capture?

                                • 13. Re: Close Script
                                  DavidJondreau

                                  Start with answering the question...

                                   

                                  If the user enters bad credentials, say a valid username and wrong password, what should happen? Then go from there. Should the user get an error message? Should they get another attempt or two? What happens if they keep failing? Should they stay in the file as the current user and be notified somehow? Does it matter if the user puts in the same username they have already? Or puts in an invalid username? What, to start, is the point of this re-login feature anyway?

                                   

                                  Set Error Capture is probably going to be involved in the script, but think about the user experience before how you implement it programmatically.

                                  • 14. Re: Close Script

                                    The simplest method is to have two scripts since it avoids confusion;

                                     

                                    Relogin:  (you may not want everyone to relogin)

                                    Re-login[]

                                    Perform Script ["Startup"]  (you may not need this if startup is called on first window open

                                     

                                    Close File use as On last Window Close to perform this script

                                     

                                    Dialog Do You Want to Close the File

                                    If ( Yes)

                                    **    <-- you can perform clean up scripts here

                                    else  (no)

                                    exit script

                                    end if

                                     

                                    Avoid using relogin with quit for sanity sake.