Choose Language Hide Translation Bar
Community Trekker

How to use 'include' to write compact code?


I repeatedly open a certain file type, which needs special import settings to opening correctly.

I would like to be able to write these import settings in a short compact form. For instance:

dt=open("fileref",import settings("string_that_parses_correctly");

where "string_that_parses_correctly" is the whole string, that holds the settings' conditions. In my case I use:


"End Of Line( CRLF, CR, LF ),

End Of Field( Tab ),

Strip Quotes( 1 ),

Use Apostrophe as Quotation Mark( 0 ), 

Scan Whole File( 1 ),

Treat empty columns as numeric( 0 ), 

Labels( 1 ),

Column Names Start( 1 ),

Data Starts( 2 ),

Lines To Read( All ),

Year Rule( "20xx")"

I captured these settings from the script generated by opening one of these files.

So is there a way to define a string, for instance as a global variable, that always is set, so that I can use it when opening the file as shown.

I hope it makes sense.


Poul Ravn Sørensen

0 Kudos
Community Trekker

Re: How to use 'include' to write compact code?

HI, I am replying to this myself.

My problems boils down the issue of combining strings into a parseable piece of jsl.

I have defined a string that contains the string, that set the special settings for the xls (csv) import. It start out: Import Settings(. . . );

Then I want dynamically to assign the file, that should be opened, like:

xls_fileid = "\\server\folder\filename";

Finally I want to combine these two like this:



But somehow get the double quotation marks mixed up.

Anyone has an example of how this is done?



0 Kudos
Super User

Re: How to use 'include' to write compact code?

You can either use \[ ... ]\ to put double quotes into a string.

Or escape them with \!".  Here are some examples.

print("Hello World");

// The following statements yield the same results:

print("\!"Hello World\!"");

print("\["Hello World"]\");

From the log:

"Hello World"

"\!"Hello World\!""

"\!"Hello World\!""

0 Kudos
Community Trekker

Re: How to use 'include' to write compact code?

Hi again, here is my JMPstart.jsl code, that sets the xls_settings (why I sometimes can't paste text into this window I do not know), :


Here are my attempts to biuld the string the opens the actual Excel file:





and then:


But the quotes keep causing errors.

Regards Poul

0 Kudos
Super User

Re: How to use 'include' to write compact code?

You're missing double quotes around the file reference.

Your command openxls doesn't do anything.  You need to add OPEN to it.

One of the nice things about JSL is its interactivity.  As you build the string, highlight it and click Run.  Check the log window and see what you've created.  Keep iterating until you get what you want.

This is possibly what you're trying to do:


xls_settings = "\[

Import Settings(

     End of line (crlf, cr, lf),

     end of field(tab),

     strip quotes(1),

     use apostrophe as quotation mark(0),

     scan whole file(1),

     treat empty columns as numeric(0),


     column names start(1),

     data starts(2),

     lines to read(all),

     year rule("20xx")


openxls = evalinsert("\[open("^xls_fileid^", ^xls_settings^) ]\")


0 Kudos