cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
smeredith68
Level I

Issues with Button Box and exiting script with Throw().

I have a script written to get user input on a start/stop date and time for production data.  In the window, there are two buttons, an OK and Cancel.  Everything associated with the output after entering the data and clicking OK is okay.  The problems are with the Cancel button.  For one, I was reading that Throw() will exit out of the script.  If you run the example below, clicking cancel will output the "PressedCancel" date to the log, but it will also output the "ContinueDateTime" and correct "ButtonPressed" data, which should be ignored due to the throw.

Another "problem" is the ability to change the spelling of the word cancel (i.e. cancelll) and the button no longer works.  If you click it, nothing happens.  Not that this is a big deal, just strange and something I can't explain. 

Anyway, below is a sampling of my code; any and all assistance is greatly appreciated.

New Window( "Report Dates and Times", <<Modal,

      V List Box(

            V List Box(

                  Text Box ("   Select Beginning and Ending Dates and Times       "),

                  Text Box (""),

                  Text Box ("              Date Format   YYYY-MM-DD               "),

                  Text Box ("              Time Format  HH-MI-SS-ss               ") ),

            H List Box(

                  V List Box(

                        Text Box (""),

                        Text Box ("Beginning Date                                   "),

                     date1 = Text Edit Box ( "2013-04-01" ) ),

                  V List Box(

                        Text Box (""),

                        Text Box ("Ending Date"),

                     date2 = Text Edit Box( "2013-04-05" ) ) ),

            H List Box(

                  V List Box(

                        Text Box (""),

                        Text Box ("Beginning Time                                   "),

                     time1 = Radio Box( {" 5:00 AM  ", " 5:00 PM  ",

                                                                                              " First Item ", " Manual   "} ),

                     time1m = Text Edit Box ( "05-00-00-00" ),

                        Text Box ("") ),

                  V List Box(

                        Text Box (""),

                        Text Box ("Ending Time   "),

                     time2 = Radio Box( {" 5:00 AM  ", " 5:00 PM  ",

                                                                                              " Last Item ", " Manual   "} ),

                     time2m = Text Edit Box ( "17-00-00-00" ),

                        Text Box ("") ) ), ),

      H List Box( Text Box ( "                      " ),

                      Button Box( "OK",

                  PressedOkay = MDYHMS( Today() );

                                          show ( PressedOkay);

                  ButtonPressed = "Pressed the OK Button"; ),

                        Button Box( "Cancel",

                  PressedCancel = MDYHMS( Today() );

                                          show ( PressedCancel);

                  ButtonPressed = "Pressed the Cancel Button";,

                                          Throw( ); ) ) );

                                         

ContinueDateTime = MDYHMS( Today() );

show( ContinueDateTime );

show( ButtonPressed );

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: Issues with Button Box and exiting script with Throw().

You do not need the throw() for your cancel button logic.  When you press Cancel the dialog box will automatically exit, because this is a modal dialog box.

Modal dialog boxes will supply an OK and Cancel button for you if you don't supply them.  The only way to exit a modal dialog box is if you press the OK or Cancel buttons.

If you want more control take out the << modal().  However, a modeless dialog box will allow users to do other things in JMP while they're open, which you may not want.

If you want to exit the script if the user presses Cancel, do the check and throw() outside of the dialog box.

        Button Box( "Cancel",

            PressedCancel = MDYHMS( Today() );

            Show( PressedCancel );

            ButtonPressed = "Pressed the Cancel Button";

        )

    )

);

                                        

ContinueDateTime = MDYHMS( Today() );

Show( ContinueDateTime );

Show( ButtonPressed );

if (buttonpressed == "Pressed the Cancel Button",

    throw("Pressed the cancel button");

);

View solution in original post

3 REPLIES 3
pmroz
Super User

Re: Issues with Button Box and exiting script with Throw().

You do not need the throw() for your cancel button logic.  When you press Cancel the dialog box will automatically exit, because this is a modal dialog box.

Modal dialog boxes will supply an OK and Cancel button for you if you don't supply them.  The only way to exit a modal dialog box is if you press the OK or Cancel buttons.

If you want more control take out the << modal().  However, a modeless dialog box will allow users to do other things in JMP while they're open, which you may not want.

If you want to exit the script if the user presses Cancel, do the check and throw() outside of the dialog box.

        Button Box( "Cancel",

            PressedCancel = MDYHMS( Today() );

            Show( PressedCancel );

            ButtonPressed = "Pressed the Cancel Button";

        )

    )

);

                                        

ContinueDateTime = MDYHMS( Today() );

Show( ContinueDateTime );

Show( ButtonPressed );

if (buttonpressed == "Pressed the Cancel Button",

    throw("Pressed the cancel button");

);

smeredith68
Level I

Re: Issues with Button Box and exiting script with Throw().

Thank you for the reply, that is what I ended up doing.  I was thinking you could imbed the throw() in the evaluation of the button and completely exit the script.  I'm not sure what the purpose of including "text" with the throw, unless it stores the text in a variable.  Perhaps this would be useful in a larger script with multiple exit points in order to log where a script exits (?).

Again, thank you for the help, it is much appreciated.

Steve

pmroz
Super User

Re: Issues with Button Box and exiting script with Throw().

The text argument to the throw() function will appear in the log, if it's called.  Useful for debugging.