cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
WHTseng
Level III

How to return value from number edit box for many items

Hi JMPers,

 

Some problems about the return values of number edit box.

I have referred to other posts(combining number box , collect all data in new window), and try to create my code.

 

Since I have many items to be given value, typing number into every item is not practical for me.

So the "New Window" and "Append" are used to dispose the return value for many items.

 

Eventually the code just return the default value(1) rather than the number I key in.

Can you help to check which steps are wrong in my code?

Thank you for great help in advanced.

 

list = {"A", "B", "C","D","E","F","G"};
val={};

nw = New Window( "example",
	v = V List Box(),
	Button Box( "OK", Set Script( nw<<close window) )
);

For( i = 1, i <= n items(list), i++,
	(v << append(
		Outline Box( "",
			H List Box(
				Text Box( list[i] ),
				exq =number Edit Box( 1 ),	
			)
		)
	) ; 
	Insert Into( val, exq<<get);
) ); show(val);

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to return value from number edit box for many items

The issue you are having, is that you are assuming that each separate specification of "exq" is being retained in a unique instance.  What is actually happening, is that they are being written on top of each other.  The code below, separates the instances.

Names Default To Here( 1 );
list = {"A", "B", "C", "D", "E", "F", "G"};
val = {};

nw = New Window( "example", v = V List Box(), Button Box( "OK", Set Script( nw << close window ) ) );

For( i = 1, i <= N Items( list ), i++,
	Insert Into( val, 1 );
	(v << append(
		Outline Box( "",
			H List Box(
				Text Box( list[i] ),
				Eval(
					Substitute(
							Expr(
								__exq__ = Number Edit Box(
									1,
									10,
									<<SetFunction( Function( {this}, val[__i__] = __exq__ << get ) )
								)
							),
						Expr( __exq__ ), Parse( "exq" || Char( i ) ),
						Expr( __i__ ), i,
					)
				), 
			)
		)
	) ; );
);
Jim

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: How to return value from number edit box for many items

The issue you are having, is that you are assuming that each separate specification of "exq" is being retained in a unique instance.  What is actually happening, is that they are being written on top of each other.  The code below, separates the instances.

Names Default To Here( 1 );
list = {"A", "B", "C", "D", "E", "F", "G"};
val = {};

nw = New Window( "example", v = V List Box(), Button Box( "OK", Set Script( nw << close window ) ) );

For( i = 1, i <= N Items( list ), i++,
	Insert Into( val, 1 );
	(v << append(
		Outline Box( "",
			H List Box(
				Text Box( list[i] ),
				Eval(
					Substitute(
							Expr(
								__exq__ = Number Edit Box(
									1,
									10,
									<<SetFunction( Function( {this}, val[__i__] = __exq__ << get ) )
								)
							),
						Expr( __exq__ ), Parse( "exq" || Char( i ) ),
						Expr( __i__ ), i,
					)
				), 
			)
		)
	) ; );
);
Jim
WHTseng
Level III

Re: How to return value from number edit box for many items

Thank you Jim, that is really a good way and helps me to understand more about "Expr", "substitute, and "Eval".

 

For << SetFunction ( Function ( {this} , val[i] = exq << get ) ),

I guess I can take the "this" away and leave an empty bracket. (I have tried and it still worked)

Will it be any potential risk to keep the bracket empty?

Thank you.

txnelson
Super User

Re: How to return value from number edit box for many items

Here is a modified version of the Example taken from 

     Help==>Scripting Index==>TextEditBox==>Set Function

that illustrates the purpose of "{this}"

Names Default To Here( 1 );
New Window( "Example",
	xx = Text Edit Box( "pw?" ),
	Text Box( "" )/* here's the sibling box, waiting to show the pw */
);
xx << SetFunction(
	Function( {this},
		this << passwordStyle( 1 );/* hide my display*/ /* put my password into my sibling's display */
		(this << sib) << settext( this << getText );
	)
);
Jim
WHTseng
Level III

Re: How to return value from number edit box for many items

Hi Jim,

 

Really thank you for the professional reply. 

I make my code based on all your suggestions, but I find the problems about sequential execution (the JSL executes all the following codes even if I haven't clicked the "OK" yet).

So I have to put all my following code into Set Script to ensure the correct executive sequence.

 

There are 2 options crossing my mind,

1) Can this method be used in the <<modal? It seems <<modal can stop the JSL running till I click "OK".

2) Does wait(0) work here? and where I should put it among the code?

 

Here is my simplified code to show my problems, I mark 2 lines as blue to show what I have done,

Names Default To Here( 1 );
list = {"A", "B", "C", "D", "E", "F", "G"};
val = {};

nw = New Window( "example",
	v = V List Box(),
	Button Box( "OK",
		Set Script(
			nw << close window;
			New Window( "result", <<modal, Text Box( val ) );
		)
	)
);


For( i = 1, i <= N Items( list ), i++,
	Insert Into( val, 1 );
	(v << append(
		Outline Box( "",
			H List Box(
				Text Box( list[i] ),
				Eval(
					Substitute(
							Expr(
								exq = Number Edit Box(
									1,
									10,
									<<SetFunction(
										Function( {this},
											val[i] = exq << get
										)
									)
								)
							),
						Expr( exq ), Parse( "exq" || Char( i ) ),
						Expr( i ), i,

					)
				),

			)
		)
	) ; );
);

nw2 = New Window( "fake result", <<modal, Text Box( val ) ); 

 

txnelson
Super User

Re: How to return value from number edit box for many items

You are correct that JMP will continue processing even without clicking OK.  Unless you do 1 of 2 things.  Make your display window a "Modal" window

nw = New Window("Test Window", Modal, ....................);

Which will force the processing to wait for the window to be cleared.

     Or

Structure your code into Functions() or Expressions, Expr(), which will not execute the code within them, until expressly called from either your window code, or from another Function() or Expr()

Jim