Subscribe Bookmark RSS Feed

Save values in text edit box

matt7109

Contributor

Joined:

Jun 9, 2017

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

Button.PNG

 

Thanks in advance! 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

Solution

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;
	)
);
-Jeff
markbailey

Staff

Joined:

Jun 23, 2011

Solution
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
Learn it once, use it forever!
6 REPLIES
Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

Solution

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;
	)
);
-Jeff
matt7109

Contributor

Joined:

Jun 9, 2017

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?

markbailey

Staff

Joined:

Jun 23, 2011

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.

Learn it once, use it forever!
markbailey

Staff

Joined:

Jun 23, 2011

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.

Learn it once, use it forever!
markbailey

Staff

Joined:

Jun 23, 2011

Solution
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
Learn it once, use it forever!
markbailey

Staff

Joined:

Jun 23, 2011

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.

Learn it once, use it forever!