cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
matt7109
Level III

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

Button.PNG

 

Thanks in advance! 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

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

View solution in original post

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

View solution in original post

6 REPLIES 6
Jeff_Perkinson
Community Manager Community Manager

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

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?

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.

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.

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

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.