cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
Thierry_S
Super User

JSL > Preserving Default Entries for Text Edit Box: Code Improvement

Hi JMP Community,

I have been toying with a short script to group column automatically based on a starting and ending string.While this work fine on my local machine, I would like to know if there is a better way to preserve default entries for the Text Edit Boxes from run to run than holding those default entries in a separate file?

Here is my code so far: Any suggestion on improving any part of it?

Names Default to Here (1);

dt = Current Data Table ();

CList = dt << get column names (string);

GList = {};


NCol = N Items (CList);

Try (dat = open("C:\AUTODAT.JMP", Invisible), 
		
		dat = new table ("AUTODAT", Invisible,
							Add Rows (2),
							New Column ("Entries", Character, Nominal, set values ({"NEW START", "NEW END"}))
								
						);
	);					
		
DefStart = column (dat, "Entries") [1];
DefEnd = column (dat, "Entries") [2];	

Dlg = New Window (" AUTO-GROUPING: ENTER SEARCH STRINGS", 
	
	<< Modal,
	Border Box (top (15), Bottom (15), Left (40), Right (40),
		V List Box (
			Text Box ("ENTER START STRING:"),
			ST = Text Edit Box (DefStart, Set Width (200)),
			
			Spacer Box (0,25),
			
			Text Box ("ENTER END STRING:"),
			ET = Text Edit Box (DefEnd, Set Width (200)),
			
			Spacer Box (0,25),
			
			Button Box ("OK", 
				StartString = ST << Get Text ();
				EndString = ET << Get Text ()
			),
			
			Button Box ("CANCEL", 
				Close( dat, NoSave );
				Throw (1))
		)
		
	)
);

Column (dat, "Entries")  << set values (Eval List ({StartString, EndString}));

dat << Save As ("C:\AUTODAT.JMP", 1);

Close (dat, NoSave);

Switch = ((Length (StartString) > 0) * 10) + (Length (EndString) > 0); 

For (i = 1, i <= NCol, i++,

	Match (Switch, 
			11,
			if(Starts With (CList [i], StartString) & Ends With (CList [i], EndString), 
				Insert into (GList, CList [i])),
			10,
			if(Starts With (CList [i], StartString), 
				Insert into (GList, CList [i])),
			1,	
			if(Ends With (CList [i], EndString), 
				Insert into (GList, CList [i])),
			0, Throw (1)
			)	
	
	
);


Group = dt << Group Columns (GList);
Thierry R. Sornasse
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: JSL > Preserving Default Entries for Text Edit Box: Code Improvement

My standard way of handling what you are doing with a saved data table, is to save the values I need to save, as JSL.  I just create a text string with the required JSL to initialize the values and save it using Save Text File().  Then on subsequent runs, I just use an Include() to initialize the values.

Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: JSL > Preserving Default Entries for Text Edit Box: Code Improvement

My standard way of handling what you are doing with a saved data table, is to save the values I need to save, as JSL.  I just create a text string with the required JSL to initialize the values and save it using Save Text File().  Then on subsequent runs, I just use an Include() to initialize the values.

Jim
Thierry_S
Super User

Re: JSL > Preserving Default Entries for Text Edit Box: Code Improvement

Hi Jim,
Always on top of things and right on the money.
Thanks,
TS
Thierry R. Sornasse