Choose Language Hide Translation Bar
Highlighted
Zihao
Level II

Rename column in a for loop

Hi 

I am trying to rename Column(3) as  "Step i" for( i = 1, i<=3, i++), and I was using the script like below. 

files={"path1", "path2", "path3"}
for (i =1, i<=3,i++,
dt = open(files[i]);
newname = "step"||i;
Column(3) << setname(newname)
);

 However, it doesn't work. It seems that the "newname" is not defined properly (I tried to show(newname) and nothing happened). 

 

Can someone help me with the correct definition of the new name with "i" in it?

 

Thanks!

Zihao

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Rename column in a for loop

The variable "i" is numeric and in order to be used in a concatenation, it needs to be a character variable.  See below

files = {"path1", "path2", "path3"};
For( i = 1, i <= 3, i++,
	dt = Open( files[i] );
	newname = "step" || Char( i );
	Column( 3 ) << setname( newname );
);
Jim

View solution in original post

2 REPLIES 2
Highlighted
txnelson
Super User

Re: Rename column in a for loop

The variable "i" is numeric and in order to be used in a concatenation, it needs to be a character variable.  See below

files = {"path1", "path2", "path3"};
For( i = 1, i <= 3, i++,
	dt = Open( files[i] );
	newname = "step" || Char( i );
	Column( 3 ) << setname( newname );
);
Jim

View solution in original post

Highlighted
txnelson
Super User

Re: Rename column in a for loop

From your first entry, you indicated that

     "newname" is not defined properly

The log would have given a message about the concatenation

 

argument should be character in access or evaluation of 'Concat' , Bad Argument( i ), "step" ||  /*###*/i/*###*/

Make sure you examine all issues found in the log.  Many times it is the first found issue that colors the additional items found.

Many times, to make it easy to see all of the errors for a given run, I will delete the log before running the script.

Jim
Article Labels

    There are no labels assigned to this post.