cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
sanqub
Level III

How do I make combo box to show unique values?

Dear All,

This script is similar to one in book "JUMP into JMP".

The script prompts user to select a "DCM", based on this selection "DieNo" list is populated.

There are couple of problems here. "DCM Number" list is not in ascending order.

Other issue, When I select a DCM number, "DieNo" list is populated. But this lists all the values, I want only unique values to be listed.

For both columns data type is char, however numeric datatype doesn't work here. Any advice on this problem.

 

/* Open the sample data table */
dt = Open( "$Desktop/JMP scripts/SampleData.jmp" );

/* Create lists of the values found in the DCMNo and Die columns*/
Unique DCM=Associative array(dt:DCMNo);
nitems(unique DCM);
DCM1= unique DCM<<get keys;
DCM=Sort Ascending(DCM1);
Unique Die=Associative array(dt:DieNo);
nitems(unique Die);
Die= unique Die<<get keys;
dt << Clear Column Selection();
dt << Clear row Selection();

/* Use New Window to create a non-modal dialog to display DCMNo and Die for user to choose. */
nw = New Window( "Choose DCM Die combination",
	hb = H List Box(
		Panel Box( "Select a DCM Number",
			select1 = Combo Box(
				DCM,  
/* Each of the following tasks are executed when the user makes a DCMNo choice.*/
				dt << Select Where( :DCMNo == DCM[select1 << get] );
				selRows = dt << Get Selected Rows;
				pb << delete;
				myDies = {};
/* The myDies list is populated with values from the selected DCMNo. */
				For( i = 1, i <= N Row( selRows ), i++,
					Insert Into( myDies, Column( dt, "DieNo" )[selRows[i]] )
				);
/* A new panel box is drawn and values shown are based on DCMNo selection. */
				hb << Append( pb = Panel Box( "Select a Die", select2 = Combo Box( myDies ) ) );
			)
		),
		pb = Panel Box( "Select a Die", Combo Box( " " ) )
	),  
/* If user clicks OK, values displayed for DCMNo and Die will be selected in table. */
	Button Box( "OK",
		nw << Close Window;
		dt << Select where( :DCMNo == DCM[select1 << get] & :DieNo == myDies[select2 << get] );
/* Selected rows are subsetted into new table. */
		rows=dt << get selected rows;
		dt << subset( Output Table Name( "Ryobi Details" ) );
	)
);

 

I am also trying to include date selection combo box. The best post and easy option for this was "date data filter".

Does JMP allow me to show a calender for dates {A wee calender as shown when we book flights from depature date to arrival date}.

 

Cheers

 

San

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How do I make combo box to show unique values?

The DCM list is alphabetically in order. You are interpreting the DCM as a number. JMP is interpreting DCM as a character string.

Why won't numeric values work for DCM or Die? That data type would solve your ordering problem.

I cleaned up a few things for a shorter solution. Here it is:

Names Default to Here( 1 );

/* Open the sample data table */
dt = Open( "$Desktop/SampleData.jmp" );

/* Create lists of the values found in the DCMNo and Die columns*/
DCM = Sort Ascending( Associative Array( dt:DCMNo ) << Get Keys );
Die = Associative Array( dt:DieNo ) << Get Keys;

selRows = dt << Get Rows Where( :DCMNo == DCM[1] );
initial Die Set = Associative Array( Column( dt, "DieNo" )[selRows] ) << Get Keys;

dt << Clear Column Selection();
dt << Clear Row Selection();

/* Use New Window to create a non-modal dialog to display DCMNo and Die for user to choose. */
nw = New Window( "Choose DCM Die combination",
	hb = H List Box(
		Panel Box( "Select a DCM Number",
			select1 = Combo Box( DCM,  
/* Each of the following tasks are executed when the user makes a DCMNo choice.*/
				selRows = dt << Get Rows Where( :DCMNo == DCM[select1 << Get] );
				myDies = Associative Array( Column( dt, "DieNo" )[selRows] ) << Get Keys;
				select2 << Set Items( myDies );
			)
		),
		Panel Box( "Select a Die",
			select2 = Combo Box( initial Die Set )
		)
	),  
/* If user clicks OK, values displayed for DCMNo and Die will be selected in table. */
	Button Box( "OK",
		nw << Close Window;
		dt << Select where( :DCMNo == DCM[select1 << Get] & :DieNo == myDies[select2 << Get] );
/* Selected rows are subsetted into new table. */
		dt << Subset( Output Table Name( "Ryobi Details" ) );
	)
);

View solution in original post

10 REPLIES 10

Re: How do I make combo box to show unique values?

The DCM list is alphabetically in order. You are interpreting the DCM as a number. JMP is interpreting DCM as a character string.

Why won't numeric values work for DCM or Die? That data type would solve your ordering problem.

I cleaned up a few things for a shorter solution. Here it is:

Names Default to Here( 1 );

/* Open the sample data table */
dt = Open( "$Desktop/SampleData.jmp" );

/* Create lists of the values found in the DCMNo and Die columns*/
DCM = Sort Ascending( Associative Array( dt:DCMNo ) << Get Keys );
Die = Associative Array( dt:DieNo ) << Get Keys;

selRows = dt << Get Rows Where( :DCMNo == DCM[1] );
initial Die Set = Associative Array( Column( dt, "DieNo" )[selRows] ) << Get Keys;

dt << Clear Column Selection();
dt << Clear Row Selection();

/* Use New Window to create a non-modal dialog to display DCMNo and Die for user to choose. */
nw = New Window( "Choose DCM Die combination",
	hb = H List Box(
		Panel Box( "Select a DCM Number",
			select1 = Combo Box( DCM,  
/* Each of the following tasks are executed when the user makes a DCMNo choice.*/
				selRows = dt << Get Rows Where( :DCMNo == DCM[select1 << Get] );
				myDies = Associative Array( Column( dt, "DieNo" )[selRows] ) << Get Keys;
				select2 << Set Items( myDies );
			)
		),
		Panel Box( "Select a Die",
			select2 = Combo Box( initial Die Set )
		)
	),  
/* If user clicks OK, values displayed for DCMNo and Die will be selected in table. */
	Button Box( "OK",
		nw << Close Window;
		dt << Select where( :DCMNo == DCM[select1 << Get] & :DieNo == myDies[select2 << Get] );
/* Selected rows are subsetted into new table. */
		dt << Subset( Output Table Name( "Ryobi Details" ) );
	)
);
lehaofeng
Level V

Re: How do I make combo box to show unique values?

Why is it that if I don't select the other numbers in the drop down box and use the default, it gives me an error; if I select the other numbers, it doesn't give me an error.
I'm version 17, mac.

jthi
Super User

Re: How do I make combo box to show unique values?

@lehaofeng  Could you create a new discussion with example script?

-Jarmo
lehaofeng
Level V

Re: How do I make combo box to show unique values?

It's Mark's script and the data provided in this post that I've found in running it that pressing the default dropdown box numbers without changing them gives me an error; selecting other numbers is fine.

/* Open the sample data table */
dt = Open( "$Desktop/SampleData.jmp" );

/* Create lists of the values found in the DCMNo and Die columns*/
DCM = Sort Ascending( Associative Array( dt:DCMNo ) << Get Keys );
Die = Associative Array( dt:DieNo ) << Get Keys;

selRows = dt << Get Rows Where( :DCMNo == DCM[1] );
initial Die Set = Associative Array( Column( dt, "DieNo" )[selRows] ) << Get Keys;

dt << Clear Column Selection();
dt << Clear Row Selection();

/* Use New Window to create a non-modal dialog to display DCMNo and Die for user to choose. */
nw = New Window( "Choose DCM Die combination",
	hb = H List Box(
		Panel Box( "Select a DCM Number",
			select1 = Combo Box( DCM,  
/* Each of the following tasks are executed when the user makes a DCMNo choice.*/
				selRows = dt << Get Rows Where( :DCMNo == DCM[select1 << Get] );
				myDies = Associative Array( Column( dt, "DieNo" )[selRows] ) << Get Keys;
				select2 << Set Items( myDies );
			)
		),
		Panel Box( "Select a Die",
			select2 = Combo Box( initial Die Set )
		)
	),  
/* If user clicks OK, values displayed for DCMNo and Die will be selected in table. */
	Button Box( "OK",
		nw << Close Window;
		dt << Select where( :DCMNo == DCM[select1 << Get] & :DieNo == myDies[select2 << Get] );
/* Selected rows are subsetted into new table. */
		dt << Subset( Output Table Name( "Ryobi Details" ) );
	)
);
jthi
Super User

Re: How do I make combo box to show unique values?

Very quickly checking the script, the issues is that the script inside combo box isn't triggered on initial creation. Most simple fix is to add something like

 

select1 << Set(2, Run Script(0));
select1 << Set(1, Run Script(1));

to end of script. This will change the value in combo box and then trigger the script once.

Other fairly easy option would be to change the script inside the Combo Box to expression and then run it once the window has been created.

 

View more...
Names Default To Here(1);


/* Open the sample data table */
dt = Open("$DOWNLOADS/SampleData.jmp");

/* Create lists of the values found in the DCMNo and Die columns*/
DCM = Sort Ascending(Associative Array(dt:DCMNo) << Get Keys);
Die = Associative Array(dt:DieNo) << Get Keys;

selRows = dt << Get Rows Where(:DCMNo == DCM[1]);
initial Die Set = Associative Array(Column(dt, "DieNo")[selRows]) << Get Keys;

dt << Clear Column Selection();
dt << Clear Select;

sel_expr = Expr(
	selRows = dt << Get Rows Where(:DCMNo == DCM[select1 << Get]);
	myDies = Associative Array(Column(dt, "DieNo")[selRows]) << Get Keys;
	select2 << Set Items(myDies);
);

/* Use New Window to create a non-modal dialog to display DCMNo and Die for user to choose. */
nw = New Window("Choose DCM Die combination",
	hb = H List Box(
		Panel Box("Select a DCM Number",
			select1 = Combo Box(
				DCM,  
/* Each of the following tasks are executed when the user makes a DCMNo choice.*/
				sel_expr
			)
		),
		Panel Box("Select a Die", select2 = Combo Box(initial Die Set))
	),  
/* If user clicks OK, values displayed for DCMNo and Die will be selected in table. */
	Button Box("OK",
		nw << Close Window;
		dt << Select where(:DCMNo == DCM[select1 << Get] & :DieNo == myDies[select2 << Get]);
/* Selected rows are subsetted into new table. */
		dt << Subset(Output Table Name("Ryobi Details"));
	)
);

sel_expr;

Or use << Get Function at the end of script with Eval

Eval(select1 << get function);
-Jarmo
lehaofeng
Level V

Re: How do I make combo box to show unique values?

Thank you !

Re: How do I make combo box to show unique values?

Also, you can use a Number Edit Box() with a date format or the new Calendar Box(). They both work well but present a different interface to the user.

Here is the Number Edit Box() approach, from the Scripting Index:

Names Default To Here( 1 );
New Window( "Example",
	fontobj = numbox = Number Edit Box( 0 )
);
numbox << Set Format( Format( "m/d/y", 12 ) );
numbox << Set( Date MDY( 10, 2, 1989 ) );

Here is the Calendar Box() solution, also taken from the Scripting Index:

 

Names Default To Here( 1 );
New Window( "Calendar Box Example",
	cal = Calendar Box()
);
pmroz
Super User

Re: How do I make combo box to show unique values?

I didn't know about the new calendar box() display box in JMP 13.  Nice!  How do you use it though?  I had to make the dialog box modal to get it to return something.

Names Default To Here( 1 );
New Window( "Calendar Box Example", << modal(),
	cal = Calendar Box()
);

selected_date = format(cal << get date, "ddMonyyyy");
print(selected_date);

Re: How do I make combo box to show unique values?

You do not need a modal window to use the Calendar Box.

The Calendar Box works like a specialized Number Edit Box. It handles dates for you so you do not have to mess with formats or convert seconds to dates or time.

See the Scripting Index or the Scripting Guide for the message protocol.