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=""></GET>
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
Re: How do I make combo box to show unique values?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;
)
);
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.
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?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()
);
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" ) );
)
);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.
Re: How do I make combo box to show unique values?@lishuanglin Could you create a new discussion with example script?
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" ) );
)
);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...
Or use << Get Function at the end of script with Eval
Eval(select1 << get function);
Re: How do I make combo box to show unique values?Thank you !