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
WanCine
Level II

How to return value from check box to desired format?

Hi,

 

I am using example from scripting index and modified as per below script.

Names Default To Here( 1 );
New Window( "Example",
	cb = Check Box(
		{"Max", "Median", "Min", "Mean", "Std Dev"},
		Print( cb << Get Selected () ) //{"Mean", "Std Dev"} or etc
	)
);

Is there any possibility to return the selected value from checkbox into "One" or One instead of {"One"}? I would like to use selected value for tabulate statistic.

 

Statistics( Max, Median, Min, Mean, Std Dev )

By any chance, can I add Cp and Cpk on the Tabulate table?

3 REPLIES 3
txnelson
Super User

Re: How to return value from check box to desired format?

The check box() is returning a List.  All you have to do is to specify which element of the list you want, and it will return it as a scalar value.  See below:

Names Default To Here( 1 );
New Window( "Example",
	cb = Check Box(
		{"Max", "Median", "Min", "Mean", "Std Dev"},
		returned = (cb << Get Selected ())[1];
		Print( returned ) //{"Mean", "Std Dev"} or etc
	)
);
Jim
WanCine
Level II

Re: How to return value from check box to desired format?

Hi Txnelson,

I try the given code, but when set to [1], it only return one value only instead of "Max","Median" and when untick all value from box it return an error. The list should be responded to whatever value that been tick or untick. Is that need to do for loop or any other better ways?

WanCine_0-1606645005446.png

WanCine_1-1606645167858.png

 

txnelson
Super User

Re: How to return value from check box to desired format?

The value returned from 

cb << Get Selected()

is a JMP List. The reason for this, is that more than one value can be selected in the Check Box().  Elements from a list can be referenced independently from the entire list, by specifying a subscript.  This was the question in your first question.  Therefore,

returned = (cb << Get Selected())[1];

returns the first item from the list.

From your latest entry, I don't believe you need to deal with the individual elements of the list, to accomplish the generation of the Tabulate.  Below is a simple example using your input window, that should show you how to handle the information coming out of the Check Box().  The code also uses one method of handling the situation when no statistic has been selected.  I changed the New Window to a "Modal" window.  A New Window by default, does not stop the processing in a JMP script.  However, a Modal window does stop the processing and waits for the user input before continuing with the processing.  To answer your question about Cp and Cpk, the Tabulate Platform does not have Cp or Cpk available.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

returned = {};

New Window( "Example",
	<<modal,
	cb = Check Box(
		{"Max", "Median", "Min", "Mean", "Std Dev"},
		returned = (cb << Get Selected());
		Print( returned ) //{"Mean", "Std Dev"} or etc
		;
	)
);

If( N Items( returned ) == 0,
	Dialog( "You must select at least one statistic" );
	Throw();
);

Tabulate(
	Show Control Panel( 0 ),
	Add Table(
		Column Table( Statistics( Eval( returned ) ), Analysis Columns( :height ) ),
		Row Table( Grouping Columns( :age ) )
	)
);

I strongly suggest that you take the time to read the Scripting Guide.  I will give you the base information about the JSL structures, such as Lists, and platform utilization, such as Tabulate, which will make your development of JMP Scripts much easier.

The Scripting Guide is found in the JMP Documentation Library, available under the Help pull down menu.

 

Jim