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