cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Aaron_Wooley
Level I

Problem With User Input as Variable

I am running into a problem with getting user input and turning it into a variable. The script that I am attempting to use for this is pasted below this paragraph. I have run the same script multiple times and without editing it, I get two different results in the log. This script is as follows:

 

 

names default to here(1);
clear log();
close all(journals, no save);
close all(data tables, no save);
 
 
defuplim = format(today(),"ddMonyyyy");
deflowlim = format(today() - in days(730), "ddMonyyyy");
 
New Window("Pick Your Dates in ddMonyyyy format",
       <<Modal,
       <<return result,
       V List Box(
              Text Box("Start Date:"),
              str1=Text Edit Box(deflowlim),
              text box("End Date:"),
              str2=Text Edit Box(defuplim)
       ),
       H List Box (Button Box ("OK"), Button Box ("Cancel"))
);
 
lowlim = str1 << get text;
uplim = str2 << get text;
 
 
lowlim=informat(lowlim);
uplim= informat(uplim);
 
show (lowlim);
show (uplim);
 

 

 

The first result from the log is what I expect the script to produce and is copied and pasted in quotes below:

lowlim = 19Jan2015;

uplim = 18Jan2017;

 

 

The other response I get from the log (again, without editing the script at all) is this:

 

 

deleted object reference: str2 << get text in access or evaluation of 'Glue' , Names Default To Here( 1 ); /*###*/Clear Log(); /*###*/

Close All( journals, no save ); /*###*/Close All( data tables, no save ); /*###*/

defuplim = Format( Today(), "ddMonyyyy" ); /*###*/deflowlim =

Format( Today() - In Days( 730 ), "ddMonyyyy" ); /*###*/

New Window( "Pick Your Dates in ddMonyyyy format",

       <<Modal,

       <<return result,

       V List Box(

              Text Box( "Start Date:" ),

              str1 = Text Edit Box( deflowlim ),

              Text Box( "End Date:" ),

              str2 = Text Edit Box( defuplim )

       ),

       H List Box( Button Box( "OK" ), Button Box( "Cancel" ) )

); /*###*/lowlim = str1 << get text; /*###*/uplim = str2 << get text; /*###*/lowlim

 = Informat( lowlim ); /*###*/uplim = Informat( uplim ); /*###*/Show( lowlim ); /*###*/

Show( uplim ) /*###*/;

 

In the following script, error marked by /*###*/

Names Default To Here( 1 ); /*###*/Clear Log(); /*###*/

Close All( journals, no save ); /*###*/Close All( data tables, no save ); /*###*/

defuplim = Format( Today(), "ddMonyyyy" ); /*###*/deflowlim =

Format( Today() - In Days( 730 ), "ddMonyyyy" ); /*###*/

New Window( "Pick Your Dates in ddMonyyyy format",

       <<Modal,

       <<return result,

       V List Box(

              Text Box( "Start Date:" ),

              str1 = Text Edit Box( deflowlim ),

              Text Box( "End Date:" ),

              str2 = Text Edit Box( defuplim )

       ),

       H List Box( Button Box( "OK" ), Button Box( "Cancel" ) )

); /*###*/lowlim = str1 << get text; /*###*/uplim = str2 << get text; /*###*/lowlim

 = Informat( lowlim ); /*###*/uplim = Informat( uplim ); /*###*/Show( lowlim ); /*###*/

Show( uplim ) /*###*/;

 

 

I’ve toggled off and on the first four lines, but get the same results (a mix of responses) regardless of whether or not they are turned off or on.

 

Any ideas what may be causing this error?

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: Problem With User Input as Variable

Try this version....it keeps the date as a numeric which is the way that JMP prefers to handle them

Names Default To Here( 1 );
Clear Log();
Close All( journals, no save );
Close All( data tables, no save );
 
 
defuplim = Today();
deflowlim = Today() - In Days( 730 );
 
New Window( "Pick Your Dates in ddMonyyyy format",
	<<Modal,
	<<return result,
	V List Box(
		Text Box( "Start Date:" ),
		str1 = Number Edit Box(
			deflowlim,
			10,
			<<SetFunction(
				Function( {that}, 
					lowlim = str1 << get
				)
			)
		),
		Text Box( "End Date:" ),
		str2 = Number Edit Box(
			defuplim,
			10,
			<<SetFunction(
				Function( {this}, 
					uplim = str2 << get
				),

			)
		),
		str1 << set format( Format( "ddMonyyyy" ) ),
		str2 << set format( Format( "ddMonyyyy" ) )
	),
	H List Box( Button Box( "OK" ), Button Box( "Cancel" ) ), 
       
);

 
Show( Format( lowlim, "ddMonyyyy" ) );
Show( Format( uplim, "ddMonyyyy" ) );
Jim

View solution in original post

Re: Problem With User Input as Variable

txnelson's script is a better way to handle dates, plus it also solves the core problem you're having with your script by doing the getting values within the boxes.

In your script, you create a modal new window, but then try to get information out of display boxes in the window after it's closed. Once a window is closed, you can't access what it held anymore - it doesn't exist anymore. This is why you're getting syntax errors for lowlim = str1 << get text;

You're almost there, though - you specified return result for the modal window, but you're not using what you're getting from it.

Without making any other changes (though txnelson's date handling is better), you can get what you want by assigning the New Window to a variable, and then getting those values (changes below in red):

 

ww = New Window("Pick Your Dates in ddMonyyyy format",
       <<Modal,
       <<return result,
       V List Box(
              Text Box("Start Date:"),
              str1=Text Edit Box(deflowlim),
              text box("End Date:"),
              str2=Text Edit Box(defuplim)
       ),
       H List Box (Button Box ("OK"), Button Box ("Cancel"))
);
 
lowlim = ww["str1"];
uplim = ww["str2"];

 

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: Problem With User Input as Variable

Try this version....it keeps the date as a numeric which is the way that JMP prefers to handle them

Names Default To Here( 1 );
Clear Log();
Close All( journals, no save );
Close All( data tables, no save );
 
 
defuplim = Today();
deflowlim = Today() - In Days( 730 );
 
New Window( "Pick Your Dates in ddMonyyyy format",
	<<Modal,
	<<return result,
	V List Box(
		Text Box( "Start Date:" ),
		str1 = Number Edit Box(
			deflowlim,
			10,
			<<SetFunction(
				Function( {that}, 
					lowlim = str1 << get
				)
			)
		),
		Text Box( "End Date:" ),
		str2 = Number Edit Box(
			defuplim,
			10,
			<<SetFunction(
				Function( {this}, 
					uplim = str2 << get
				),

			)
		),
		str1 << set format( Format( "ddMonyyyy" ) ),
		str2 << set format( Format( "ddMonyyyy" ) )
	),
	H List Box( Button Box( "OK" ), Button Box( "Cancel" ) ), 
       
);

 
Show( Format( lowlim, "ddMonyyyy" ) );
Show( Format( uplim, "ddMonyyyy" ) );
Jim
Aaron_Wooley
Level I

Re: Problem With User Input as Variable

Thanks, that was very helpful! Keeping the date numeric makes a lot of sense and requires less converting.

TFranke
Level II

Re: Problem With User Input as Variable

New to jmp and trying to understand how this sequence works - could someone explain how this aspect of the code works? Looks like it saves the box input to a local variable without needing to output text box results to an array, but unsure how the function works to accomplish this. 

<<SetFunction(
				Function( {that}, 
					lowlim = str1 << get
				)
			)

 

txnelson
Super User

Re: Problem With User Input as Variable

One needs to look at more of the code than what you specified, in order to interpret it

deflowlim = Today() - In Days( 730 );

str1 = Number Edit Box(
	deflowlim,
	10,
	<<SetFunction(
		Function( {that}, 
			lowlim = str1 << get
		)
	)
)

What is basically going on here, is setting up a data entry field to allow the user to enter a date.  The type of data entry field is a Number Edit Box(). (See documentation and example of Number Edit Box() in the Scripting Index under the Help pull down menu).

neb1.PNG

 

The documentation states that form of the Number Edit Box() is:

y = Number Edit Box( initValue, <width> )

A variable called "str1" is assigned as a pointer to the Number Edit Box(). In the illustration, this is the "y" variable

The variable, "deflowlim" is used to set the initial value to be displayed in the Number Edit Box(). In the illustration, this is the "initValue".

The width of the Number Edit Box() is set to 10 characters

 

As can be seen in the above documentation listing, there are a large number of Item Messages that can be passed to the Number Edit Box() object.  The message in question from the code you are asking about, is "Set Function".  Here is the listing from the Scripting Index

neb2.PNG

What this message does, is to set up a piece of JSL that is run whenever something is changed in the Number Edit Box().

lowlim = str1 << get

So every time, something is changed in the Number Edit Box(), a "get" message is passed to "str1", which is the Number Edit Box()

The "get" message is:

neb3.PNG

Returns the number currently entered in the edit box

and the returned number is assigned to the variable "lowlim".

Therefore, "lowlim" is a scalar variable, which can be referenced in subsequent JSL.  Only a scalar variable needs to be assigned, since JMP dates are stored as a continuous numeric data value.

 

I hope this clears up your question(s).

Jim
TFranke
Level II

Re: Problem With User Input as Variable

Got it, that explains why removing the Set Function caused variables to be stored as null. Without the Set function it doesn't update with each change made to the edit box. Thank you for the thorough explanation!

Re: Problem With User Input as Variable

txnelson's script is a better way to handle dates, plus it also solves the core problem you're having with your script by doing the getting values within the boxes.

In your script, you create a modal new window, but then try to get information out of display boxes in the window after it's closed. Once a window is closed, you can't access what it held anymore - it doesn't exist anymore. This is why you're getting syntax errors for lowlim = str1 << get text;

You're almost there, though - you specified return result for the modal window, but you're not using what you're getting from it.

Without making any other changes (though txnelson's date handling is better), you can get what you want by assigning the New Window to a variable, and then getting those values (changes below in red):

 

ww = New Window("Pick Your Dates in ddMonyyyy format",
       <<Modal,
       <<return result,
       V List Box(
              Text Box("Start Date:"),
              str1=Text Edit Box(deflowlim),
              text box("End Date:"),
              str2=Text Edit Box(defuplim)
       ),
       H List Box (Button Box ("OK"), Button Box ("Cancel"))
);
 
lowlim = ww["str1"];
uplim = ww["str2"];