cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
lukasz
Level IV

How to enter and pass data from List Box?

Hello,

I would like to provide a list of parameters or variables from the window level (for example copied from excel) and pass this list (for example by clicking OK) further to create an another list for a SQL query. Can I do that with some type of List Box (something like in the picture below)? What other methods could be used to do that? Best regards.

lukasz_0-1626641206201.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to enter and pass data from List Box?

Below is an example. Create function (parsePaste in example) to handle the input and do modifications you want to: remove duplicates,  replace row changes with something, remove duplicated separators... After pressing OK this will return one string, then you can modify the returned string to fit in to your SQL (Words() and Concat Items() as examples).

Names Default To Here(1);

parsePaste = function({tempStr}, {Default Local},
	tempStr = Regex(tempStr, "\r\n", ",", GLOBALREPLACE); //replace row changes with ,
	tempStr = Substitute(tempStr, ",,", ","); //replace double ,, with one ,
	tempStr = Regex(tempStr, ",$", "", GLOBALREPLACE); //remove , if last character
	return(tempStr);
);

win2 = New Window("Example", << Modal,
	V List Box(
		Text Box("Add Serialnumbers:"),
		teb = Text Edit Box("", << set width(200), << set nlines(3), 
			<< Set Function(Function({this},
				this << set text(parsePaste(this << get text));
			))
		),
		H List Box(
			Button Box("OK", listStr = teb << get text),
			Button Box("Cancel")
		)
	)
);
show(listStr);
temp = Words(listStr, ",");
temp = "'" || Concat Items(temp, "','") ||"'";
show(temp);

 

 

 

-Jarmo

View solution in original post

4 REPLIES 4
jthi
Super User

Re: How to enter and pass data from List Box?

Couple of questions/ideas to get you going:

  1. Do you want that user selects the interesting serial numbers from pre-created list? You could use list box
  2. Would you like for user to be able to copy-paste serial numbers from somewhere which will be converted to SQL-query? You could use Text Edit Box with a parsing function.
  3. Possibly both of above? I would most likely try to avoid this, as if the user is copy pasting values from somewhere, they can make the selection already there what they want to be included.
  4. Do you want to use modal?

Check Scripting Index for: Modal (how to build modal window), List Box, Text Edit Box, Concat Items (how to convert JMP list into string)

 

Quick example with List Box which will set text box value below OK button and print selected values as list to log when ok is pressed:

 

Names Default To Here(1);

serialList = {"a1", "b2", "c3", "d4"};
win2 = New Window("Example",
	V List Box(
		lb = List Box(serialList, width(200), nlines(6)),
		Button Box("OK", Show(lb << get selected); tb << Set Text(char(lb << get selected))),
		tb = Text Box("");
	)
);

 

jthi_0-1626646784434.png

 

-Jarmo
lukasz
Level IV

Re: How to enter and pass data from List Box?

Hello,

thank you for suggestions. I would like to be able to copy serial numbers from somewhere and then pass them further using parsing function, so the option 2 and together with modal window. I will try with Text Edit Box.

Best regards

jthi
Super User

Re: How to enter and pass data from List Box?

Below is an example. Create function (parsePaste in example) to handle the input and do modifications you want to: remove duplicates,  replace row changes with something, remove duplicated separators... After pressing OK this will return one string, then you can modify the returned string to fit in to your SQL (Words() and Concat Items() as examples).

Names Default To Here(1);

parsePaste = function({tempStr}, {Default Local},
	tempStr = Regex(tempStr, "\r\n", ",", GLOBALREPLACE); //replace row changes with ,
	tempStr = Substitute(tempStr, ",,", ","); //replace double ,, with one ,
	tempStr = Regex(tempStr, ",$", "", GLOBALREPLACE); //remove , if last character
	return(tempStr);
);

win2 = New Window("Example", << Modal,
	V List Box(
		Text Box("Add Serialnumbers:"),
		teb = Text Edit Box("", << set width(200), << set nlines(3), 
			<< Set Function(Function({this},
				this << set text(parsePaste(this << get text));
			))
		),
		H List Box(
			Button Box("OK", listStr = teb << get text),
			Button Box("Cancel")
		)
	)
);
show(listStr);
temp = Words(listStr, ",");
temp = "'" || Concat Items(temp, "','") ||"'";
show(temp);

 

 

 

-Jarmo
lukasz
Level IV

Re: How to enter and pass data from List Box?

Hello, sorry for late response. This is exactly what I wanted to implement. Thank you very much. Best regards