Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
Matt_C
Level I

Run date box before deleting data

In the script below all the data from my table is deleted before I can run the data boxes. 

I am trying to delete any data outside of my date range.

Can I use modal somehow?

 

Thx - Matt

 

_____________________________________________________________

//Open and reset all names, ask for date
Names Default To Here( 1 );
dt_run = Open( "data.jmp");

//wait for open
wait(0);

dt_run << clear row states;
dt_run << Clear Column Selection();

startNW = New Window( "Start",
 ///<<Modal,///does not allow script or user to go on until text box answered
 StartDate << Max Date( Col Max( :name( "Date" ) ) ) << Min Date( Col Min( :Name( "Date" ) ) );
 
 
 StartDate = Calendar Box(),
 Button Box( "OK",
  startNW << close window;
  StartDate << Set Function( Function( {this, date}, theStartDate = StartDate << Get Date ) );
 )
 
);


runEndDate = Expr(
 endNW = New Window( "End",
  EndDate = Calendar Box(),
  Button Box( "OK",
   endNW << close window;
   runSelect;
  )
 );
 endDate << Max Date( Col Max( :name( "Date" ) ) ) << Min Date( Col Min( :Name( "Date" ) ) );
 EndDate << Set Function( Function( {this, date}, theEndDate = endDate << Get Date ) );
);

runSelect = Expr(
 dt_run << select where( :Name( "Date" ) > theStartDate & :Name( "Date" ) < theEndDate )
);

dt_run << Invert Row Selection();
dt_run << Delete Rows();

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Run date box before deleting data

I have reworked your script to allow for conditional flow.

//Open and reset all names, ask for date
Names Default To Here( 1 );
dt_run = Open( "Data_date.jmp" );

//wait for open
Wait( 0 );
dt_run << clear row states;
dt_run << Clear Column Selection();
startNW = New Window( "Start Day (note: day after date)",
	<<modal,
	StartDate = Calendar Box(),
	Button Box( "OK", startNW << close window );
	StartDate << Max Date( Col Max( dt_run:Date ) ) << Min Date( Col Min( dt_run:Date ) );
	StartDate << Set Function(
		Function( {this, date},
			Show( "xx" );
			theStartDate = StartDate << Get Date;
		);
		Show( thestartdate );
	);
);
If( startnw["button"] == 1,
	endNW = New Window( "End",
		<<modal,
		EndDate = Calendar Box(),
		Button Box( "OK", endNW << close window );
		EndDate << Max Date( Col Max( :name( "Date" ) ) ) << Min Date( Col Min( :Name( "Date" ) ) );
		EndDate << Set Function( Function( {this, date}, theEndDate = endDate << Get Date ) );
	)
);
If( endNW["Button"] == 1,
	dt_run << select where( :Name( "Date" ) > theStartDate & :Name( "Date" ) < theEndDate );
	dt_run << Invert Row Selection();
	dt_run << Delete Rows();
   
	dt_run << Save( "date_selection.jmp" );
	Close All( Data Tables, No Save );
	
	dt_run = Open( "date_selection.jmp" );

///Graphs
	New Window( "ProtoCP_Monitor - Variability Chart",
		V List Box(
			Variability Chart(
				Y( :PV waves ),
				X( :Date, :Time ),
				Std Dev Chart( 0 ),
				SendToReport(
					Dispatch( {"Variability Chart for PV"}, "2", ScaleBox, {Min( 0 ), Max( 2 ), Inc( 0.02 ), Minor Ticks( 0 )} )
				)
			), 
 //more charts but deleted script to shorten post
		)
	) << Journal();

// Save and Close The Journal
	Current Journal() << save Journal( "stuff.jrn" );
);

Jim

View solution in original post

3 REPLIES 3
Highlighted
txnelson
Super User

Re: Run date box before deleting data

I believe that by moving the StartDate line after the window components are defined, will get you what you want

//Open and reset all names, ask for date
Names Default To Here( 1 );
dt_run = Open( "data.jmp" );
//wait for open

Wait( 0 );
dt_run << clear row states;
dt_run << Clear Column Selection();
startNW = New Window( "Start", 
 <<Modal,///does not allow script or user to go on until text box answered

	StartDate = Calendar Box();,
	Button Box( "OK",
		startNW << close window;
		StartDate << Set Function( Function( {this, date}, theStartDate = StartDate << Get Date ) );
	),
	
	StartDate << Max Date( Col Max( :name( "Date" ) ) ) << Min Date( Col Min( :Name( "Date" ) ) );
 
);

runEndDate = Expr(
	endNW = New Window( "End",
		EndDate = Calendar Box(),
		Button Box( "OK",
			endNW << close window;
			runSelect;
		)
	);
	endDate << Max Date( Col Max( :name( "Date" ) ) ) << Min Date( Col Min( :Name( "Date" ) ) );
	EndDate << Set Function( Function( {this, date}, theEndDate = endDate << Get Date ) );
);
runSelect = Expr(
	dt_run << select where( :Name( "Date" ) > theStartDate & :Name( "Date" ) < theEndDate )
);
dt_run << Invert Row Selection();
dt_run << Delete Rows();
Jim
Highlighted
Matt_C
Level I

Re: Run date box before deleting data

Got the delete to work as show below.

Same issue though the script takes off and does the charts before I am done with the Calender box()

//Open and reset all names, ask for date
Names Default To Here( 1 );
dt_run = Open( "Data_date.jmp");
//wait for open
wait(0);
dt_run << clear row states;
dt_run << Clear Column Selection();
startNW = New Window( "Start Day (note: day after date)",
<<modal,
 StartDate = Calendar Box();,
 Button Box( "OK",
  startNW << close window;
  runEndDate;
 )
 
);
StartDate << Max Date( Col Max( :name( "Date" ) ) ) << Min Date( Col Min( :Name( "Date" ) ) );

StartDate << Set Function( Function( {this, date}, theStartDate = StartDate << Get Date ) );
runEndDate = Expr(
 endNW = New Window( "End",
 <<modal,
  EndDate = Calendar Box();,
  Button Box( "OK",
   endNW << close window;
   runSelect;
  )
 );
 EndDate << Max Date( Col Max( :name( "Date" ) ) ) << Min Date( Col Min( :Name( "Date" ) ) );
 EndDate << Set Function( Function( {this, date}, theEndDate = endDate << Get Date ) );
);
runSelect = Expr(
 dt_run << select where( :Name( "Date" ) > theStartDate & :Name( "Date" ) < theEndDate );
 dt_run << Invert Row Selection();
 dt_run << Delete Rows();
   
 dt_run << Save( "date_selection.jmp");
 Close All( Data Tables, No Save );
);


Names Default To Here( 1 );
dt_run = Open( "date_selection.jmp");

///Graphs
New Window( "ProtoCP_Monitor - Variability Chart",
 V List Box(
  Variability Chart(
   Y( :PV waves),
   X( :Date, :Time ),
   Std Dev Chart( 0 ),
   SendToReport(
    Dispatch(
     {"Variability Chart for PV"},
     "2",
     ScaleBox,
     {Min( 0 ), Max( 2 ), Inc( 0.02 ), Minor Ticks( 0 )}
    )
   )
  ),
 //more charts but deleted script to shorten post
)<< Journal();

// Save and Close The Journal
Current Journal() << save Journal("stuff.jrn");

 

how do I keep the script held until the calender box is complete?

Thanks

Highlighted
txnelson
Super User

Re: Run date box before deleting data

I have reworked your script to allow for conditional flow.

//Open and reset all names, ask for date
Names Default To Here( 1 );
dt_run = Open( "Data_date.jmp" );

//wait for open
Wait( 0 );
dt_run << clear row states;
dt_run << Clear Column Selection();
startNW = New Window( "Start Day (note: day after date)",
	<<modal,
	StartDate = Calendar Box(),
	Button Box( "OK", startNW << close window );
	StartDate << Max Date( Col Max( dt_run:Date ) ) << Min Date( Col Min( dt_run:Date ) );
	StartDate << Set Function(
		Function( {this, date},
			Show( "xx" );
			theStartDate = StartDate << Get Date;
		);
		Show( thestartdate );
	);
);
If( startnw["button"] == 1,
	endNW = New Window( "End",
		<<modal,
		EndDate = Calendar Box(),
		Button Box( "OK", endNW << close window );
		EndDate << Max Date( Col Max( :name( "Date" ) ) ) << Min Date( Col Min( :Name( "Date" ) ) );
		EndDate << Set Function( Function( {this, date}, theEndDate = endDate << Get Date ) );
	)
);
If( endNW["Button"] == 1,
	dt_run << select where( :Name( "Date" ) > theStartDate & :Name( "Date" ) < theEndDate );
	dt_run << Invert Row Selection();
	dt_run << Delete Rows();
   
	dt_run << Save( "date_selection.jmp" );
	Close All( Data Tables, No Save );
	
	dt_run = Open( "date_selection.jmp" );

///Graphs
	New Window( "ProtoCP_Monitor - Variability Chart",
		V List Box(
			Variability Chart(
				Y( :PV waves ),
				X( :Date, :Time ),
				Std Dev Chart( 0 ),
				SendToReport(
					Dispatch( {"Variability Chart for PV"}, "2", ScaleBox, {Min( 0 ), Max( 2 ), Inc( 0.02 ), Minor Ticks( 0 )} )
				)
			), 
 //more charts but deleted script to shorten post
		)
	) << Journal();

// Save and Close The Journal
	Current Journal() << save Journal( "stuff.jrn" );
);

Jim

View solution in original post

Article Labels

    There are no labels assigned to this post.