I think you are right; you might need to use parse() to convert the string to an expression.
Here's another approach you can take which avoids strings and manipulates the expressions directly:
// testing data (I modified your end of field with a tab, below)
filelist = {"$sample_data\..\Import Data\bigclass.txt"};
x = 1;
// build an expression with a placeholder COLUMNSEXPR
openstmt = Expr(
Open(
FileList[x],
COLUMNSEXPR, // << placeholder for columns(...)
Import Settings( End Of Line( CRLF, CR, LF ), End Of Field( tab, CSV( 0 ) ),
Strip Quotes( 1 ), Column Names Start( 1 ), Data Starts( 1 ) )
)
);
// if you run the openstmt function now, it will import all the columns
//
// eval(openstmt);
// build a list using {} to make it easy to manipulate
COLUMNSLIST = {};
// insert the column you want to keep
Insert Into( COLUMNSLIST, Expr( New Column( "Col1", Character, "Nominal" ) ) );
// insert 5 omit columns...
For( i = 1, i < 5, i += 1,
Insert Into( COLUMNSLIST, Expr( Omitted Column( . ) ) )
);
// COLUMNSLIST looks like this:
//{New Column( "Col1", Character, "Nominal" ), Omitted Column( . ),
//Omitted Column( . ), Omitted Column( . ), Omitted Column( . )}
// convert the {...} to columns(...)
Substitute Into( COLUMNSLIST, Expr( {} ), Expr( columns ) );
//show(nameexpr(COLUMNSLIST)); shows this:
//columns(New Column("Col1", Character, "Nominal"),
//Omitted Column(.), Omitted Column(.),
//Omitted Column(.), Omitted Column(.))
//
// if you leave out the nameexpr() it will (try to) evaluate rather than
// retrieving the expression for display. columns() is not a function in
// JSL, so evaluating makes an error message.
// nameexpr(openstmt) still show COLUMNSEXPR. replace it:
Substitute Into( openstmt, Expr( COLUMNSEXPR ), Name Expr( COLUMNSLIST ) );
// nameexpr(openstmt) is now
//Open(
// FileList[x],
// columns(
// New Column( "Col1", Character, "Nominal" ),
// Omitted Column( . ),
// Omitted Column( . ),
// Omitted Column( . ),
// Omitted Column( . )
// ),
// Import Settings(
// End Of Line( CRLF, CR, LF ),
// End Of Field( tab, CSV( 0 ) ),
// Strip Quotes( 1 ),
// Column Names Start( 1 ),
// Data Starts( 1 )
// )
//)
Eval( openstmt ); // reads just the first column of the table
You could also do something similar by manipulating text, rather than expressions, and then
eval(parse( " the text you built ") )
Use the technique you are most comfortable with; there will be a minor speed improvement manipulating the expressions, but insignificant compared to reading a file from disk.
Note that the final statement above still depends on the value of X to choose a file to open, so there is no need to rebuild the expression.
Craige