Subscribe Bookmark RSS Feed

Problem With User Input as Variable

Highlighted
Aaron_Wooley

New Contributor

Joined:

Jan 18, 2017

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

Joined:

Jun 22, 2012

Solution

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
melaniedrake

Staff

Joined:

May 30, 2014

Solution

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

 

3 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Solution

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

New Contributor

Joined:

Jan 18, 2017

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

melaniedrake

Staff

Joined:

May 30, 2014

Solution

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