BookmarkSubscribe
Choose Language Hide Translation Bar
Kirk_A
Occasional Contributor

How to use Radio Boxes

I am brand new to JMP scripting and trying to self teach. I created a radio box:

New Window( "Example",
panelbox("Confidence Interval",
rb = Radio Box(
{"90%", "95%", "98%", "99%"},
Show( rb << Get() ),
),

 

My current question is how can I use the variable rb?

 

I tried this if(then) statement:

If(
	:rb == "95%", 
// then
	:x = 1.96,
	:rb == "90%", :x = 1.645,
	:rb == "98%", :x = 2.326,
	:rb == "99%", :x = 2.576,

)

but get this error message: "Name Unresolved: rb in access or evaluation of 'rb' , :rb/*###*/"

 

Here is the whole code. 

 

 

Names Default To Here( 1 );
computeResults = Expr(
	If(
		:rb == "95%", 
// then
		:x = 1.96,
		:rb == "90%", :x = 1.645,
		:rb == "98%", :x = 2.326,
		:rb == "99%", :x = 2.576, 

	)
);
New Window( "Example",
	Panel Box( "Confidence Interval",
		rb = Radio Box(
			{"90%", "95%", "98%", "99%"},
			Show( rb << Get() ), 
		), 
	), 

	H Center Box( Button Box( "Calculate Minimum Sample Size", computeResults ) ), 

	V List Box( Text Box( "" ), ciolb = Panel Box( "Result", x = Number Edit Box( "" ) ) )
);

 

 

Thanks for any help or suggestions. I'll be reading the scripting manual and check back later.

 

0 Kudos
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
vince_faller
Super User

Re: How to use Radio Boxes

You're scoping the variables as columns when you do :rb.  You have to send the graphic objects << messages. 

 

Names Default To Here( 1 );
computeResults = Expr(
	match(rb << Get Selected,
		"95%", x << Set(1.96), 
		"90%", x << Set(1.645), 
		"98%", x << Set(2.326), 
		"99%", x << Set(2.576)
	);
);

New Window( "Example",
	Panel Box( "Confidence Interval",
		rb = Radio Box(
			{"90%", "95%", "98%", "99%"},
			Show( rb << Get() ), 


		), 

	), 

	H Center Box( Button Box( "Calculate Minimum Sample Size", computeResults ) ), 

	V List Box( Text Box( "" ), ciolb = Panel Box( "Result", x = Number Edit Box( "" ) ) )
);

//Or you could make the radiobox actually just change it


New Window( "Example",
	Panel Box( "Confidence Interval",
		rb = Radio Box(
			{"90%", "95%", "98%", "99%"},
			<<Set Function(
				Function({self}, 
					match(self << Get Selected,
						"95%", x << Set(1.96), 
						"90%", x << Set(1.645), 
						"98%", x << Set(2.326), 
						"99%", x << Set(2.576)
					);
				)
			), 
		), 

	), 

	//H Center Box( Button Box( "Calculate Minimum Sample Size", computeResults ) ), 

	V List Box( Text Box( "" ), ciolb = Panel Box( "Result", x = Number Edit Box( 1.645 ) ) )
);
Vince Faller - Predictum
txnelson
Super User

Re: How to use Radio Boxes

The issue you are having is that you are a little confused as what the "X" variable is.  In the code that @vince_faller  provided, "X" is associated with a DisplayBox object.  More specifically, it is a NumberEditBox(), display object.  The NumberEditBox() is an Object in your window.  To set and get the values in the object, you use <<Set and <<Get messages.  And, as long as the display window remains open, you can get and set the values in that object.  

z = x << get;

However, most scripts are structured to display a window to get and set information, but then close the window to do further calculations.  Therefore, one typicaly moves the required values out of the display objects into standard JSL scalers, lists or matricies.  For the NumberEditBox() I typically use a simple <<Set Function message.  It executes each time the value in the NumberEditBox() changes.

New Window( "Example",
	Panel Box( "Confidence Interval",
		rb = Radio Box(
			{"90%", "95%", "98%", "99%"},
			<<Set Function(
				Function( {self},
					Match( self << Get Selected,
						"95%", x << Set( 1.96 ),
						"90%", x << Set( 1.645 ),
						"98%", x << Set( 2.326 ),
						"99%", x << Set( 2.576 )
					)
				)
			), 

		), 

	), 

	H Center Box(
		Button Box( "Calculate Minimum Sample Size", computeResults )
	), 

	V List Box(
		tb = Text Box( "" ),
		ciolb = Panel Box( "Result",
			x = Number Edit Box(
				1.645,
				7,
				<<set function( Function( {this}, z = this << get ) )
			)
		)
	)
);

or you could actually just set the z value in the Radito Box()

New Window( "Example",
	Panel Box( "Confidence Interval",
		rb = Radio Box(
			{"90%", "95%", "98%", "99%"},
			<<Set Function(
				Function( {self},
					Match( self << Get Selected,
						"95%", x << Set( 1.96 ); z = x << get;,
						"90%", x << Set( 1.645 ); z = x << get;,
						"98%", x << Set( 2.326 ); z = x << get;,
						"99%", x << Set( 2.576 ); z = x << get;
					)
				)
			), 

		), 

	)

	H Center Box(
		Button Box( "Calculate Minimum Sample Size", computeResults )
	), 

	V List Box(
		tb = Text Box( "" ),
		ciolb = Panel Box( "Result",
			x = Number Edit Box(
				1.645
			)
		)
	)
);
Jim
12 REPLIES 12
Kirk_A
Occasional Contributor

Re: How to use Radio Boxes

edit: I'm sorry, the goal is to recognize which radio box is marked and then print out the z-score.

0 Kudos
Highlighted
vince_faller
Super User

Re: How to use Radio Boxes

You're scoping the variables as columns when you do :rb.  You have to send the graphic objects << messages. 

 

Names Default To Here( 1 );
computeResults = Expr(
	match(rb << Get Selected,
		"95%", x << Set(1.96), 
		"90%", x << Set(1.645), 
		"98%", x << Set(2.326), 
		"99%", x << Set(2.576)
	);
);

New Window( "Example",
	Panel Box( "Confidence Interval",
		rb = Radio Box(
			{"90%", "95%", "98%", "99%"},
			Show( rb << Get() ), 


		), 

	), 

	H Center Box( Button Box( "Calculate Minimum Sample Size", computeResults ) ), 

	V List Box( Text Box( "" ), ciolb = Panel Box( "Result", x = Number Edit Box( "" ) ) )
);

//Or you could make the radiobox actually just change it


New Window( "Example",
	Panel Box( "Confidence Interval",
		rb = Radio Box(
			{"90%", "95%", "98%", "99%"},
			<<Set Function(
				Function({self}, 
					match(self << Get Selected,
						"95%", x << Set(1.96), 
						"90%", x << Set(1.645), 
						"98%", x << Set(2.326), 
						"99%", x << Set(2.576)
					);
				)
			), 
		), 

	), 

	//H Center Box( Button Box( "Calculate Minimum Sample Size", computeResults ) ), 

	V List Box( Text Box( "" ), ciolb = Panel Box( "Result", x = Number Edit Box( 1.645 ) ) )
);
Vince Faller - Predictum
Kirk_A
Occasional Contributor

Re: How to use Radio Boxes

Thank you very much for the reply. I will definitely study up more on match and that "Set Function" you suggested. Thank you again!

0 Kudos
txnelson
Super User

Re: How to use Radio Boxes

You mention that you are self teaching JSL.  Given that, I suggest you take the time to read the Scripting Guide

     Help==>Books==>Scripting Guide

and that you become very familiar with the Scripting Index.  In the index, you will find all of the messages, etc. that can be sent to the functions and objects, and will give you examples of each.  Below is the example that is referenced in the section of the guide for Radio Button(), using a Set Function() for processing

setfun.PNG

Jim
Kirk_A
Occasional Contributor

Re: How to use Radio Boxes

Thanks for the heads up, definitely going to look that over closely.

0 Kudos
Kirk_A
Occasional Contributor

Re: How to use Radio Boxes

Ummmm ....

 

I used this code:

Match( rb << Get Selected,
	"95%", x << Set( 1.96 ),
	"90%", x << Set( 1.645 ),
	"98%", x << Set( 2.326 ),
	"99%", x << Set( 2.576 )
);

 

to display the z-score for a chosen CI via radio buttons. The x assigned and the correct z-score displayed.

 

I now want to use the z-score in a formula, but am getting this error: 

Send Expects Scriptable Object in access or evaluation of 'Send' , z << /*###*/Set( 1.96 ) /*###*/

Is the x-value as obtained in the above code not a numeric value I can use in a formula? Is there a way to "force" it to be/act numeric?

0 Kudos
txnelson
Super User

Re: How to use Radio Boxes

The issue you are having is that you are a little confused as what the "X" variable is.  In the code that @vince_faller  provided, "X" is associated with a DisplayBox object.  More specifically, it is a NumberEditBox(), display object.  The NumberEditBox() is an Object in your window.  To set and get the values in the object, you use <<Set and <<Get messages.  And, as long as the display window remains open, you can get and set the values in that object.  

z = x << get;

However, most scripts are structured to display a window to get and set information, but then close the window to do further calculations.  Therefore, one typicaly moves the required values out of the display objects into standard JSL scalers, lists or matricies.  For the NumberEditBox() I typically use a simple <<Set Function message.  It executes each time the value in the NumberEditBox() changes.

New Window( "Example",
	Panel Box( "Confidence Interval",
		rb = Radio Box(
			{"90%", "95%", "98%", "99%"},
			<<Set Function(
				Function( {self},
					Match( self << Get Selected,
						"95%", x << Set( 1.96 ),
						"90%", x << Set( 1.645 ),
						"98%", x << Set( 2.326 ),
						"99%", x << Set( 2.576 )
					)
				)
			), 

		), 

	), 

	H Center Box(
		Button Box( "Calculate Minimum Sample Size", computeResults )
	), 

	V List Box(
		tb = Text Box( "" ),
		ciolb = Panel Box( "Result",
			x = Number Edit Box(
				1.645,
				7,
				<<set function( Function( {this}, z = this << get ) )
			)
		)
	)
);

or you could actually just set the z value in the Radito Box()

New Window( "Example",
	Panel Box( "Confidence Interval",
		rb = Radio Box(
			{"90%", "95%", "98%", "99%"},
			<<Set Function(
				Function( {self},
					Match( self << Get Selected,
						"95%", x << Set( 1.96 ); z = x << get;,
						"90%", x << Set( 1.645 ); z = x << get;,
						"98%", x << Set( 2.326 ); z = x << get;,
						"99%", x << Set( 2.576 ); z = x << get;
					)
				)
			), 

		), 

	)

	H Center Box(
		Button Box( "Calculate Minimum Sample Size", computeResults )
	), 

	V List Box(
		tb = Text Box( "" ),
		ciolb = Panel Box( "Result",
			x = Number Edit Box(
				1.645
			)
		)
	)
);
Jim
Kirk_A
Occasional Contributor

Re: How to use Radio Boxes

This feel very unintuitive. So Set and Get are simialr but different. Thanks again for the direction. 

0 Kudos
txnelson
Super User

Re: How to use Radio Boxes

Set and Get are exact opposites.  If we look at

Match( self << Get Selected,
						"95%", x << Set( 1.96 ); z = x << get;,
						"90%", x << Set( 1.645 ); z = x << get;,
						"98%", x << Set( 2.326 ); z = x << get;,
						"99%", x << Set( 2.576 ); z = x << get;
					)

The variable "X" is pointing to a display object.  So to communicate with a display object, one passes messages to the object.  Thus to assign a value to the object one passes the message to the object to "Set" the value.  Thus,

x << Set( 1.96 ); 

The variable "Z" is just a memory variable( a scaler value).  To assign a value to a scaler variable, one just uses an "=", such as

a = 42;
theParameterValue = b + c * 24;

but in your case, you want to set the scaler variable "Z" to the value from the Display Object, "X".  So to do that, one uses the "="  to assign the value to variable "Z", but has to pass the message, "<< get" to the Display Object "X" to retrieve its current value. 

z = x << get;

The statements could have also been written:

x << Set( 1.96 ); z = 1.96;

which might have been more understandable.

 
Jim
0 Kudos