cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar

"open" in JSL

This is probably laughably simple but I'm brand new to scripting...

I have written a script that manipulates a data table. That all works fine. Right now it just operates on the current data table.

What I would like to have it do is actually import the raw text file as the first step when I run the script. However, I want to be able to select which file I'm importing and I want the script to automatically apply certain arguments to the table. I can just use:

open();

but then I need to select which columns to import, select character types, etc. I would like to have the script do those things automatically each time. So I want to include arguments that are the same each time but don't want the file path/name to be the same each time. Any ideas?

Thanks.
1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: "open" in JSL

I think the following may be what you need:

1. Open a file manually. In the dataset see if there's a red triangle with "Source" next to it. Click on the red triangle and select "Edit Script".

2. This should bring up a script window with a giant Open() command. Save this script but make the filename a variable (e.g. import_filename).

3. Use the Pick File() command to find the file you want to import. Set the import_filename variable = to this file.

4. Plug the import_filename variable into your previously saved Open() command from step 2.

Regards,
Peter

View solution in original post

4 REPLIES 4
pmroz
Super User

Re: "open" in JSL

I think the following may be what you need:

1. Open a file manually. In the dataset see if there's a red triangle with "Source" next to it. Click on the red triangle and select "Edit Script".

2. This should bring up a script window with a giant Open() command. Save this script but make the filename a variable (e.g. import_filename).

3. Use the Pick File() command to find the file you want to import. Set the import_filename variable = to this file.

4. Plug the import_filename variable into your previously saved Open() command from step 2.

Regards,
Peter

Re: "open" in JSL

Thanks. I think that's getting me close but I must not be understanding something. Here's basically what the beginning of my script looks like:

import_filename=pick file("select file","D:\Documents and Settings\Bob\My Documents\Projects\");

dt=Open(
"import_filename",
columns(
col1= Character,
col2 = Character,
col3 = Character,
. = Omit,
),
);

Do you see what I'm doing wrong?
pmroz
Super User

Re: "open" in JSL

Remove the double quotes around "import_filename". It's a variable and you're giving it a literal string.

dt=Open(
import_filename,
columns(
col1= Character,
col2 = Character,
col3 = Character,
. = Omit,
),
);

Re: "open" in JSL

Thanks! As I said, I'm a newbie. It works perfectly now.