- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
script to add two column
i am trying to add two columns.
two of the column has name abcd and efgh
following line works:
dt_tab << New Column( newcolumn, formula( :name( "abcd" ) + :name( "efgh" ) ) );
but following code is throwing an error
name1 = "abcd";
name2 ="efgh";
dt_tab << New Column( name1 || "3", formula(:name(name1) + :name(name2)));
why is the 2nd method not working?
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: script to add two column
My error......I had placed an ")" wrong, and should have used the As Column() function, not the Column() function
Names Default To Here( 1 );
dt_tab = New Table( "Example",
Add Rows( 4 ),
New Column( "abcd",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 2, 3, 4] )
),
New Column( "efgh",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [5, 6, 7, 8] )
)
);
name1 = "abcd";
name2 = "efgh";
Eval(
Substitute(
Expr(
dt_tab <<
New Column( name1 || "3",
formula(
As Column( __name1__ )
+As Column( __name2__ )
)
)
),
Expr( __name1__ ), name1,
Expr( __name2__ ), name2
)
);
Jim
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: script to add two column
The reason this is not working, is that neither the :Name() function nor the Formula() element does not parse the contents of the function before execution. You need to create the exact JSL before execution
name1 = "abcd";
name2 = "efgh";
Eval(
Substitute(
Expr(
dt_tab << New Column( name1 || "3",
formula( Column( __name1__ ) ) + Column( __name2__ )
)
),
Expr( __name1__ ), name1,
Expr( __name2__ ), name2
)
);
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: script to add two column
Thank you Jim. I tried this but still not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: script to add two column
My error......I had placed an ")" wrong, and should have used the As Column() function, not the Column() function
Names Default To Here( 1 );
dt_tab = New Table( "Example",
Add Rows( 4 ),
New Column( "abcd",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 2, 3, 4] )
),
New Column( "efgh",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [5, 6, 7, 8] )
)
);
name1 = "abcd";
name2 = "efgh";
Eval(
Substitute(
Expr(
dt_tab <<
New Column( name1 || "3",
formula(
As Column( __name1__ )
+As Column( __name2__ )
)
)
),
Expr( __name1__ ), name1,
Expr( __name2__ ), name2
)
);
Jim