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
Thierry_S
Super User

Newb JSL Question: How to get the content of a Text Edit Box into a variable?

Hi,

 

I'm a beginner in JSL (JMP 13.1) and I'm struggling with the interactive dialog logic especially how to extract the content of a Text Edit Box into a variable.

 

Here is a snippet of a JSL script that does not work (i.e. the variable "prefix" is not updated with the content of the Text Edit Box "tt1).

prefix = "";
win = New Window ("   TEST   ",
	<< Modal,
	<< On Validate (
		
		if (Is Missing (prefix),0,1);
	),

	H List Box (
		Text Box ("  Define Prefix "),
		tt1 = Text Edit Box (""),
		prefix = (tt1 << Get Text) // I cannot figure out how to assign the content of "tt1" to "prefix""
	),	
);

Show (tt1, prefix);

Thank you for your help.

 

Sincerely,

 

TS

 

Thierry R. Sornasse
3 ACCEPTED SOLUTIONS

Accepted Solutions
Craige_Hales
Super User

Re: Newb JSL Question: How to get the content of a Text Edit Box into a variable?

Try this

win = New Window( "Set a Value in Number Edit Box",
	<<Modal,
	<<Return Result,
	Text Box( "Set this value" ),
	numberbox = Number Edit Box( 42 ),
	texteditbox = TextEdit Box( "this one too" ),
	Button Box( "OK" ),
	Button Box( "Cancel" )
);
Write( win["numberbox"] );
Write( win["texteditbox"] );
show(win);

When the modal window closes, the returned value is a list of the content of the boxes that had assignments:

win = {numberbox = 3.1415, texteditbox = "argyle", Button(1)};

The button(1) means the OK button, -1 is the cancel button.

win["numberbox"] is a way to ask the list to search its members for the assignment and return the value.

Craige

View solution in original post

txnelson
Super User

Re: Newb JSL Question: How to get the content of a Text Edit Box into a variable?

Place the script that sets the prefix value, into the script that is executed when the text edit box is changed

Names Default To Here( 1 );
prefix = "";
win = New Window( "   TEST   ",
	<<Modal,
	<<On Validate(
		
		If( Is Missing( prefix ),
			0,
			1
		)
	), 

	H List Box(
		Text Box( "  Define Prefix " ),
		tt1 = Text Edit Box( "", <<set script( prefix = (tt1 << Get Text) ) ) // I cannot figure out how to assign the content of "tt1" to "prefix""
	),

);

Show( tt1, prefix );
Jim

View solution in original post

David_Burnham
Super User (Alumni)

Re: Newb JSL Question: How to get the content of a Text Edit Box into a variable?

You are currently placing the assignment script in a function that is expecting display boxes.  Here are the different places you could put the line:

1/ based on your code, you are validating the window based on the value of the prefix, so you could put a line prior to the conditional test

2/ after the new window call, to unpick the contents of the window once the user has clicked OK

3/ inside an onClose event, created using similar syntax to onValidate (achieves the same as (2) but is more elegant and more robust going across Windows/Mac platforms

4/ inside an event handler attached to the display box itself

Given that you are validating the form I would choose the first option:

prefix = "";
win = New Window ("   TEST   ",
	<< Modal,
	<< On Validate (
		prefix = tt1 << Get Text;
		if (Is Missing (prefix),0,1);
	),

	H List Box (
		Text Box ("  Define Prefix "),
		tt1 = Text Edit Box (""),
	),	
);

Show (tt1, prefix);

 

-Dave

View solution in original post

5 REPLIES 5
Craige_Hales
Super User

Re: Newb JSL Question: How to get the content of a Text Edit Box into a variable?

Look at the examples using "Return Result" in https://www.jmp.com/support/help/14-2/constructors-for-new-windows.shtml

Also in your example:

	H List Box (
		Text Box ("  Define Prefix "),
		tt1 = Text Edit Box (""),
		prefix = (tt1 << Get Text) // I cannot figure out how to assign the content of "tt1" to "prefix""
	),	

the tt1=... and prefix=... arguments to HListBox are executed when the hlistbox is being created. tt1 results in a textEditBox that HListBox keeps. I'm pretty certain the prefix value, "", is being ignored by the hlistbox. I'm away from my desk, but I think the textEditBox might be able to run some JSL as a second argument when the value changes...maybe you want something closer to tt1=texteditbox("", prefix=(tt1<<gettext) ).  If that works, you might not need to use "Return Result".

Craige
Thierry_S
Super User

Re: Newb JSL Question: How to get the content of a Text Edit Box into a variable?

Hi Craig,

Thank you for your help: I already tried moving the line "prefix = (tt1 << Get Text) within the Text Edit Box call but I'm getting an error message "The display box 'TextEditBox' does not recognize the message 'Assign' ".
I have not yet figured out how incorporate the Return Result switch
Thierry R. Sornasse
Craige_Hales
Super User

Re: Newb JSL Question: How to get the content of a Text Edit Box into a variable?

Try this

win = New Window( "Set a Value in Number Edit Box",
	<<Modal,
	<<Return Result,
	Text Box( "Set this value" ),
	numberbox = Number Edit Box( 42 ),
	texteditbox = TextEdit Box( "this one too" ),
	Button Box( "OK" ),
	Button Box( "Cancel" )
);
Write( win["numberbox"] );
Write( win["texteditbox"] );
show(win);

When the modal window closes, the returned value is a list of the content of the boxes that had assignments:

win = {numberbox = 3.1415, texteditbox = "argyle", Button(1)};

The button(1) means the OK button, -1 is the cancel button.

win["numberbox"] is a way to ask the list to search its members for the assignment and return the value.

Craige
txnelson
Super User

Re: Newb JSL Question: How to get the content of a Text Edit Box into a variable?

Place the script that sets the prefix value, into the script that is executed when the text edit box is changed

Names Default To Here( 1 );
prefix = "";
win = New Window( "   TEST   ",
	<<Modal,
	<<On Validate(
		
		If( Is Missing( prefix ),
			0,
			1
		)
	), 

	H List Box(
		Text Box( "  Define Prefix " ),
		tt1 = Text Edit Box( "", <<set script( prefix = (tt1 << Get Text) ) ) // I cannot figure out how to assign the content of "tt1" to "prefix""
	),

);

Show( tt1, prefix );
Jim
David_Burnham
Super User (Alumni)

Re: Newb JSL Question: How to get the content of a Text Edit Box into a variable?

You are currently placing the assignment script in a function that is expecting display boxes.  Here are the different places you could put the line:

1/ based on your code, you are validating the window based on the value of the prefix, so you could put a line prior to the conditional test

2/ after the new window call, to unpick the contents of the window once the user has clicked OK

3/ inside an onClose event, created using similar syntax to onValidate (achieves the same as (2) but is more elegant and more robust going across Windows/Mac platforms

4/ inside an event handler attached to the display box itself

Given that you are validating the form I would choose the first option:

prefix = "";
win = New Window ("   TEST   ",
	<< Modal,
	<< On Validate (
		prefix = tt1 << Get Text;
		if (Is Missing (prefix),0,1);
	),

	H List Box (
		Text Box ("  Define Prefix "),
		tt1 = Text Edit Box (""),
	),	
);

Show (tt1, prefix);

 

-Dave