Subscribe Bookmark RSS Feed

Dynamic creation of column formula

shoffmeister

Community Trekker

Joined:

Mar 27, 2015

Hi folks,

 

 

I'm trying to write a script that will create some variants of a date-time-column in the table. For example:

 

1. User selects the date-time-column in a dialog: E.g.: :DateTime

2. => the script creates a new column using a formula: Hour(:DateTime)

 

My problem is to figure out how to create a formula that is referencing a column specified by the user. Current ly I am doing this:

time = .;
New Window( "Generate Time Indicators",
	<<Modal,
	V List Box(
		Text Box( "Time Variable" ),
		ts = Col List Box( Current Data Table(), all, time = (ts << Get Selected)[1] ),
		Text Box( "(Chose indicators to create)" ),
		cb = Check Box(
			{"Day of Week (numeric)", "Day of Week (character)", "Month (numeric)", "Month (character)", "Year"}
		)
	)
);

inds = cb << Get Selected();

If( Contains( inds, "Month (numeric)" ),
	fml = Eval Expr( Month( As Column( Expr( time ) ) ) );
	Current Data Table() << New Column( "Month", Formula( Name Expr( fml ) ) );
);

 

This script works for me, but does not for work for any of my co-workers. We are all running JMP 13.1.0. One person is running JMP on a Mac, while all others are using Windows 10 (me including).

 

Here is what my boss gets:

 

formula bug1.JPGformula bug2.JPG

For me everything works fine:

fine.png

Thanks a lot to any1 who can tell me whats going on here!

 

 

1 REPLY
txnelson

Super User

Joined:

Jun 22, 2012

I have been able to replicate your managers findings by selecting the time column in the data table before running the script.  When the script then appears, the column shows up as selected.  If check the new column format to use, and then click on OK, the error occurs.  What is happening, is that your time value is not getting set, because the user hasn't clicked on the Col List Box(), so the script you have specified for the Col List Box() does not get run.

 

Probably the easiest way to fix this would be to place the script from the Col List Box() in the Check Box() script, since you know it has to be selected.

Jim