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
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.
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 );
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);
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".
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.
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 );
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);