Subscribe Bookmark RSS Feed

How to make item appear more than once in a List Box?

pmroz

Super User

Joined:

Jun 23, 2011

Hello Jmpers,




Is there a way for a listbox to contain more than a set of unique values? I'm building a listbox in a dialog box and it needs to contain the same value(s) more than once. But it appears that JMP is only displaying the unique values.




Here's some sample code:





style="font-size: 10pt; font-family: "Courier New"; color: black;">separator_list

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">
{

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"<LF>"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"/"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"<SPACE>"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"("

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">")"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"<LF>"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"/"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"<SPACE>"

style="font-size: 10pt; font-family: "Courier New"; color: black;">}

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">

 





style="font-size: 10pt; font-family: "Courier New"; color: black;">tab_dlg

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">NewWindow

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"Unique
Listbox Values"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">

 





style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">PanelBox

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"Select
Separator"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">separator_lb

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">ListBox

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: black;">separator_list

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
width(

style="font-size: 10pt; font-family: "Courier New"; color: teal;">200

style="font-size: 10pt; font-family: "Courier New"; color: black;">)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
nLines(

style="font-size: 10pt; font-family: "Courier New"; color: teal;">7

style="font-size: 10pt; font-family: "Courier New"; color: black;">))

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">           
)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">panelbox

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"Action"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">     

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">hlistbox

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">           

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">button
box

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"Close"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
action

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: teal;">1

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">                             
tab_dlg

style="font-size: 10pt; font-family: "Courier New"; color: navy;"><<

style="font-size: 10pt; font-family: "Courier New"; color: black;">
close window)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">           
)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">     
)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; line-height: 115%; font-family: "Courier New"; color: black;">)

style="font-size: 10pt; line-height: 115%; font-family: "Courier New"; color: navy;">;





Thanks,


Peter
8 REPLIES
Hi Peter

This is curious. I have just written a "get unique values" function because I wanted a list box to contain only unique values from a list.

Display boxes seem to exhibit different behaviour depending on whether they are contained in a modal or non-model window.

Using the Dialog function instead of New Window results in the entire list being shown:

separator_list = {"", "/", "", "(", ")", "", "/", ""};

Dialog(
lb = ListBox(separator_list )
)

I'm not suggesting that you use a modal window, just pointing out the difference in behaviour.

BTW, how did you retain the formatting of the code in your message ?
pmroz

Super User

Joined:

Jun 23, 2011

Curious about modal vs non-modal. Unfortunately I'm stuck with non-modal because of the callback functionality.

To post code retaining formatting is a bit tricky:

1. Copy the code from the JSL editor
2. Paste it into MS Word.
3. Recopy the program text in Word
4. Paste the text into an HTML editor. I use Nvu (http://www.nvu.com/)
5. In Nvu, go to the Source tab and copy the HTML between and
6. Paste the HTML into the JMP discussion forum window.

It sounds more complicated than it is. Worth it for readability. Maybe JMP will update their forum software instead?

Regards,
Peter
pmroz

Super User

Joined:

Jun 23, 2011

Hey _Stig_ care to share your function to calculate unique values in a list (not a dataset)?

I.e.
list1 = {"aa", "aa", "aa", "bb", "cc", "cc"};
list2 = get unique values(list1);

print(list2);

{"aa", "bb", "cc"}

Thanks,
Peter
Peter

Here are a couple of implementations:



or :

pmroz

Super User

Joined:

Jun 23, 2011

Thanks Stig.  I ended up doing something similar to your first
approach.  I have the luxury of having a sorted list, so it's
a bit faster:




style="font-size: 10pt; font-family: "Courier New"; color: black;">unique_cells

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">
{}

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">prev_value

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"XyZaBc#$%"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">k

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: teal;">0

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">for

style="font-size: 10pt; font-family: "Courier New"; color: black;">
(i

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: teal;">1

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
i

style="font-size: 10pt; font-family: "Courier New"; color: navy;"><=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">nitems

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: black;">cell_list)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
i

style="font-size: 10pt; font-family: "Courier New"; color: navy;">++,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">    
one_cell

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">
cell_list[i]

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">    

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">if

style="font-size: 10pt; font-family: "Courier New"; color: black;">
(one_cell

style="font-size: 10pt; font-family: "Courier New"; color: navy;">!=

style="font-size: 10pt; font-family: "Courier New"; color: black;">
prev_value

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">        
prev_value

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">
one_cell

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">        
k

style="font-size: 10pt; font-family: "Courier New"; color: navy;">++;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">        
unique_cells[k]

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">
one_cell

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">    
)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; line-height: 115%; font-family: "Courier New"; color: black;">)

style="font-size: 10pt; line-height: 115%; font-family: "Courier New"; color: navy;">;




Regards,

Peter
aim

Community Trekker

Joined:

Jun 23, 2011

Here is short and fast version:




style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none"
class=MsoNormal>
style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">Get_unique_values

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">=

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">

style="FONT-FAMILY: 'Courier New'; COLOR: #0000dd; FONT-SIZE: 10pt">Function

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">(

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">
{in_list}

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">,

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">


style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none"
class=MsoNormal>
style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">
style="mso-tab-count: 1">     
{Default
Local}

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">,

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">



style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none"
class=MsoNormal>
style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">
style="mso-tab-count: 1">     
tmp

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">=

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">
[

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">=>

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">

style="FONT-FAMILY: 'Courier New'; COLOR: teal; FONT-SIZE: 10pt">0

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">]

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">;

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">



style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none"
class=MsoNormal>
style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">
style="mso-tab-count: 1">     

style="FONT-FAMILY: 'Courier New'; COLOR: #0000dd; FONT-SIZE: 10pt">Insert
Into

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">(

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">
tmp

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">,

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt"> in_list
)

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">;

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">



style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none"
class=MsoNormal>
style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">
style="mso-tab-count: 1">     
tmp

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt"><<

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt"> get
keys

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">;

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">



style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none"
class=MsoNormal>
style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">)

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">;

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">



style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none"
class=MsoNormal>
style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">

 



style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none"
class=MsoNormal>
style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt">///Example

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">



style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none"
class=MsoNormal>
style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">try_list

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">=

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">
{

style="FONT-FAMILY: 'Courier New'; COLOR: purple; FONT-SIZE: 10pt">"aaa"

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">,

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">

style="FONT-FAMILY: 'Courier New'; COLOR: purple; FONT-SIZE: 10pt">"ss"

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">,

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">

style="FONT-FAMILY: 'Courier New'; COLOR: purple; FONT-SIZE: 10pt">"dd"

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">,

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">

style="FONT-FAMILY: 'Courier New'; COLOR: purple; FONT-SIZE: 10pt">"dd"

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">,

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">

style="FONT-FAMILY: 'Courier New'; COLOR: purple; FONT-SIZE: 10pt">"dd"

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">,

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">

style="FONT-FAMILY: 'Courier New'; COLOR: purple; FONT-SIZE: 10pt">"dd"

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">,

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">

style="FONT-FAMILY: 'Courier New'; COLOR: purple; FONT-SIZE: 10pt">"aaa"

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">}

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">;

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">



style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none"
class=MsoNormal>
style="FONT-FAMILY: 'Courier New'; COLOR: #0000dd; FONT-SIZE: 10pt">Show

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">(

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">
Get_unique_values( try_list ) )

style="FONT-FAMILY: 'Courier New'; COLOR: navy; FONT-SIZE: 10pt">;

style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt">



class=MsoNormal>

 

ms

Super User

Joined:

Jun 23, 2011

Amazingly simple solution! Took me a while to figure out how it works. I did not know that the Insert commands were allowed to leave out arguments when applied to associative arrays.
That's a really useful technique. Thanks Aim