cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
luqi
Level II

Opening multiple DataTables

So I want to create an application that will prompt the user to specify a certain number of data tables after which the user can pick the corresponding tables. Also I would like to add columns to each of those tables. I am still new to jmp/jsl but below is my script which of course does not work, Any help is well appreciated;

New Window( "Number of Data Tables",

  <<Modal,

  Text Box( "Number of Data Tables" ),

  variablebox = Number Edit Box(),

  Button Box( "OK" ),

  Button Box( "Cancel" )

);

N = Variablebox << get;

For( i = 1, i <= N Items( dt ), i++,

  dt = Open()

Names Default To Here(1);

dt=Current Data Table (i);

dt << New Column("ColumnA", Numeric, continous, Format("Best", 5));

dt << New Column("ColumnB", Numeric, continous, Format("Best", 5));

);


PS: I know the script for adding additonal columns has to go in the For loop somehow but if I can even open the data tables, then how can i even add the columns.

PMroz​  jordanhiller@jmp​  chris.kirchbergCHFieldsMarkBailey

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Level X

Re: Opening multiple DataTables

So now I understand that your question is about selection of which files to open . . .

It looks like 'PickFile()' may already be flexible enough do what you require (see 'Help > Scripting Index').

In so far as it needs to interact with the operating system, you might expect some slight difference between Windows and OS/X, and it seems that's the case here. Unfortunately, though, I don't have a Windows machine on which to test the code below (I'm also assuming that for multiple selections 'PickFile()' will indeed return a list):

Names Default To Here( 1 );

// Use 'PickFile()' to get a list of files to open (Windows only)

fileList =

Pick File(

"Select one of more files", // Prompt

"$DESKTOP", // Initial folder

{"JMP Files|jmp;jsl;jrn", "All Files|*"}, // List of file filters to apply (ignored by OS/X)

1, // Initial file filter to apply (index of item in the list above)

0, // Save flag - Specify either a 'Save' or 'Open' window. Set a value of 1 or 0 respectively.

Empty(),// Default file

1 // Multiple - If 'Save Flag' = 0, using a value of 1 allows more than one file to be opened (ignored by OS/X)

);

// If only a single file is selected, fileList will not be a list, so we need to build it for ourselves

if(!IsList(fileList), fileList = EvalList({fileList}));

// Open the files and store their corresponding JMP table names

tableNames = {};

for(f=1, f<=NItems(fileList), f++,

dt = Open(fileList[f]);

InsertInto(tableNames, dt << getName);

);

View solution in original post

8 REPLIES 8
ian_jmp
Level X

Re: Opening multiple DataTables

I think you need to give just a little more detail on what you are after, please.

Assuming that for the first step you want to allow selections from open tables (rather than selections of which tables to open), then take a look at:

NamesDefaultToHere(1);

// Show the open tables in the session, and let the user select some

openTables = {};

For (t=1, t<=NTable(), t++, InsertInto(openTables, DataTable(t) << getName));

nw =

NewWindow("Select the Tables You Require",

lb = ListBox(openTables),

LineUpBox(NCol(2), ButtonBox("OK", OKscript), ButtonBox("Cancel", nw << closeWindow))

);

// Do something with the selected tables (in this case, just print)

OKScript =

Expr(

nw << CloseWindow;

selectedTables = lb << getSelected;

ClearLog();

if (NItems(selectedTables) > 0,

For (t=1, t<=NItems(selectedTables), t++,

Print("Table "||selectedTables[t]||" selected.")

),

Print("No tables selected.")

);

);

luqi
Level II

Re: Opening multiple DataTables

Hello Ian,

Thank you for the feedback, I will try my best to explain better. I want the script that asks a user the number of data table to open, then prompts the user to select the tables to open corresponding to the number asked earlier.  Algorithm will look like below:

  1. Run script
  2. User is asked how many data table to open (A modal window will make things easier)    ex: User types in say 3
  3. User is then asked to pick any 3 data tables it prefers
  4. Add "Column A" and "Column B" to each of the 3 data tables

I hope this helps clarify the problem better. Thanks once again!

ian_jmp
Level X

Re: Opening multiple DataTables

So now I understand that your question is about selection of which files to open . . .

It looks like 'PickFile()' may already be flexible enough do what you require (see 'Help > Scripting Index').

In so far as it needs to interact with the operating system, you might expect some slight difference between Windows and OS/X, and it seems that's the case here. Unfortunately, though, I don't have a Windows machine on which to test the code below (I'm also assuming that for multiple selections 'PickFile()' will indeed return a list):

Names Default To Here( 1 );

// Use 'PickFile()' to get a list of files to open (Windows only)

fileList =

Pick File(

"Select one of more files", // Prompt

"$DESKTOP", // Initial folder

{"JMP Files|jmp;jsl;jrn", "All Files|*"}, // List of file filters to apply (ignored by OS/X)

1, // Initial file filter to apply (index of item in the list above)

0, // Save flag - Specify either a 'Save' or 'Open' window. Set a value of 1 or 0 respectively.

Empty(),// Default file

1 // Multiple - If 'Save Flag' = 0, using a value of 1 allows more than one file to be opened (ignored by OS/X)

);

// If only a single file is selected, fileList will not be a list, so we need to build it for ourselves

if(!IsList(fileList), fileList = EvalList({fileList}));

// Open the files and store their corresponding JMP table names

tableNames = {};

for(f=1, f<=NItems(fileList), f++,

dt = Open(fileList[f]);

InsertInto(tableNames, dt << getName);

);

luqi
Level II

Re: Opening multiple DataTables

Thanks Ian, you have been really helpful. I tested the code above and it works on windows too. I was also able to edits and incorporate the code into my work. However, I can only open one file at a time. From your explanation, adding the latter 1 in the Pick file funtion should allow multiple files to be opened but that doesn't work on my computer (windows by the way).  Is there any ways to get around this so I can open multiple files at the same time? Thanks

ian_jmp
Level X

Re: Opening multiple DataTables

Hmmm. I'll ask R&D, because it feels like that should work.

It's always best to use inbuilt functions if at all possible, but you could always do something like:

NamesDefaultToHere(1);

dir = PickDirectory("Move to the folder containing your files", "$DESKTOP");

nw = NewWindow("Open Multiple Files",

PanelBox("Select one or more files",

lb = ListBox(FilesInDirectory(dir)),

LineUpBox(NCol(2),

ButtonBox("OK", OKScript),

ButtonBox("Cancel", nw << closeWindow)

)

)

);

OKScript =

Expr(

nw << closeWindow;

files = lb << getSelected;

For(f=1, f<=NItems(files), f++, Open(dir||"/"||files[f]));

);


Re: Opening multiple DataTables

The multiple argument to PickFile() is a keyword, not a boolean. Try this:

Pick File(

       "Select one of more files", // Prompt

       "$sample_data", // Initial folder

       {"JMP Files|jmp;jsl;jrn", "All Files|*"}, // List of file filters to apply (ignored by OS/X)

       1, // Initial file filter to apply (index of item in the list above)

       0, // Save flag - Specify either a 'Save' or 'Open' window. Set a value of 1 or 0 respectively.

       Empty(), // Default file

       "multiple" // Multiple - If 'Save Flag' = 0, using a value of 1 allows more than one file to be opened (ignored by OS/X)

);

Note that in order to use the multiple argument, all the previous arguments must be specified - you can't leave off the 2 flags and the default file, for example.

ian_jmp
Level X

Re: Opening multiple DataTables

Of course! Many thanks for straightening me out, Melanie . . .

Anyone reading this thread should also note that (contrary to the comments in the code) the keyword "multiple' is respected by OS/X and Windows.

luqi
Level II

Re: Opening multiple DataTables

Oh wow that works. Thanks!!!