- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Save values in text edit box
Hi,
If I have a window, such as the one below, and the user enters some values in the text boxes. How could I save these numerical values into an array? For example, if someone typed in 1, 2, 3 ,and 4 into the text boxes, when they press OK, I would like these values to be saved into an array.
new window("test",
text edit box(""),
text edit box(""),
text edit box(""),
text edit box(""),
button box("OK");
)
Thanks in advance!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Save values in text edit box
You need to add a script argument to your Button Box(). It will collect the values from the text edit boxes and close the window.
Something like this:
nw = New Window( "test",
a = Text Edit Box( "" ),
b = Text Edit Box( "" ),
c = Text Edit Box( "" ),
d = Text Edit Box( "" ),
Button Box( "OK",
foo = Eval List(
{a << get text, b << get text, c << get text, d <<get text}
);
nw << close window;
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Save values in text edit box
dlg = New Window( "Enter Many Numbers", << Modal,
Outline Box( "Data Entry",
Table Box(
String Col Box( "Variable", { "a", "b", "c", "d", "e" } ),
nceb = Number Col Edit Box( "Value", J( 5, 1, . ) )
)
),
H List Box(
Button Box( "OK",
input = nceb << Get As Matrix;
),
Button Box( "Cancel" )
)
);
If( dlg["Button"] == -1,
Throw( "User cancelled" );
);
// Do something with input values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Save values in text edit box
You need to add a script argument to your Button Box(). It will collect the values from the text edit boxes and close the window.
Something like this:
nw = New Window( "test",
a = Text Edit Box( "" ),
b = Text Edit Box( "" ),
c = Text Edit Box( "" ),
d = Text Edit Box( "" ),
Button Box( "OK",
foo = Eval List(
{a << get text, b << get text, c << get text, d <<get text}
);
nw << close window;
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Save values in text edit box
Thank you! If there was a much larger number of boxes, is there any way to automate this using a loop rather than an a, b, c, and d?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Save values in text edit box
If you use a Number Col Edit Box instead of individual Text Edit Box objects, then your button script can send the message Get As Matrix to return all of them as a column vector.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Save values in text edit box
You can place a String Col Box to the left of the Number Col Edit Box for labels if you like and enclose both of the columns in a Table Box to neatly organize it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Save values in text edit box
dlg = New Window( "Enter Many Numbers", << Modal,
Outline Box( "Data Entry",
Table Box(
String Col Box( "Variable", { "a", "b", "c", "d", "e" } ),
nceb = Number Col Edit Box( "Value", J( 5, 1, . ) )
)
),
H List Box(
Button Box( "OK",
input = nceb << Get As Matrix;
),
Button Box( "Cancel" )
)
);
If( dlg["Button"] == -1,
Throw( "User cancelled" );
);
// Do something with input values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Save values in text edit box
In addition to Jeff's answer, you should consider other display boxes. A Text Edit Box is a fine and versatile input object but there are others that are more specialized for a given purpose, If you expect a numeric value, consider a Number Edit Box. If you expect multiple, possibly related numeric values, then consider a Number Col Edit Box.
You should definitely consider reading the JSL guide about constructing windows, dialogs in particular. See Help > Books > Scripting Guide.