Subscribe Bookmark RSS Feed

moving column named via string variable to after another column also named via string variable

galactus3000

Contributor

Joined:

Nov 9, 2016

How do I  move a column referenced by a string variable to after another column also referenced by a string variable in table st

 

zzz = Column(cnm);
colst = {zzz};
Eval(Eval Expr(Expr(st<<MoveSelectedColumns(colst, After(yyy)))));

 

my Locals show that

Variable cnm has the Value "ppg 1000" of type String

Variable yyy has the Value Column("lxt 1000") of type Column

Variable zzz has the Value Column("ppg 1000") of type Column

Variable colst has the Value {zzz} of type List

 

Thought I would need to use Eval, Eval Expr, Expr, etc to get this to work, but cannot seem to get it right.

Please help.  Thanks in advance.

 

Cheers

Galactus3000

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz

Super User

Joined:

Jun 23, 2011

Solution

Here's another way that builds a string dynamically and then executes it via eval(parse()).  

 

st = New Table( "Untitled", Add Rows( 2 ),
	New Column( "lxt 1000", Character, "Nominal", Set Values( {"a", "b"} ) ),
	New Column( "Column 2", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 2] )
	),
	New Column( "ppg 1000", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [3, 4] )
	)
);

wait(2);
cnm = "ppg 1000";
yyy = "lxt 1000";

move_expr = evalinsert("\[st << Move Selected Columns({"^cnm^"}, After("^yyy^"))]\");
eval(parse(move_expr));
3 REPLIES
ian_jmp

Staff

Joined:

Jun 23, 2011

Here's one way:

NamesDefaultToHere(1);

dt = NewTable("MoveColumns");
dt << addMultipleColumns("Column ", 10, AfterLast, Numeric);

Wait(2);
cols = dt << getColumnNames("String");
RemoveFrom(cols, 8, 3);
afterCol = "Column 08";
moveCMD = Expr(dt << moveSelectedColumns(colsTBD, After(afterColTBD)));
SubstituteInto(moveCMD, Expr(colsTBD), cols, Expr(afterColTBD), afterCol);
moveCMD 

 

pmroz

Super User

Joined:

Jun 23, 2011

Solution

Here's another way that builds a string dynamically and then executes it via eval(parse()).  

 

st = New Table( "Untitled", Add Rows( 2 ),
	New Column( "lxt 1000", Character, "Nominal", Set Values( {"a", "b"} ) ),
	New Column( "Column 2", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 2] )
	),
	New Column( "ppg 1000", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [3, 4] )
	)
);

wait(2);
cnm = "ppg 1000";
yyy = "lxt 1000";

move_expr = evalinsert("\[st << Move Selected Columns({"^cnm^"}, After("^yyy^"))]\");
eval(parse(move_expr));
vince_faller

Super User

Joined:

Mar 17, 2015

only do the expr around the colst.  if you're doing an evalExpr() around a whole expr(), you're effectively doing nothing.  

 

Eval(EvalExpr(dt << MoveSelectedColumns(Expr(colst), After(yyy))))

 

it's probably a good idea to do:
colst = Evallist({zzz});

unless you're trying to have colst be a list of references instead of a list of columns