Subscribe Bookmark RSS Feed

How do I make combo box to show unique values?

sanqub

Community Trekker

Joined:

Jan 11, 2016

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
markbailey

Staff

Joined:

Jun 23, 2011

Solution

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" ) );
	)
);
Learn it once, use it forever!
5 REPLIES
markbailey

Staff

Joined:

Jun 23, 2011

Solution

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" ) );
	)
);
Learn it once, use it forever!
markbailey

Staff

Joined:

Jun 23, 2011

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()
);
Learn it once, use it forever!
pmroz

Super User

Joined:

Jun 23, 2011

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);
markbailey

Staff

Joined:

Jun 23, 2011

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.

Learn it once, use it forever!
pmroz

Super User

Joined:

Jun 23, 2011

The scripting index and guide are somewhat weak with regard to this new function.  The examples in the scripting guide could be beefed up a bit.  Here's a better one that displays the calendar.  When you select a date and click OK that is printed in the log window.

Names Default To Here( 1 );
nw = New Window( "Calendar Box Example", 
	cal = Calendar Box(),
	ok_button = button box("OK",
		selected_date = format(cal << get date, "ddMonyyyy");
		print(selected_date);
		nw << close window;
	)
);