Ask a Question

Dynamically change column name in Project Variables

sachinmk08
New Contributor

Dynamically change column name in Project Variables

Is it possible to create table with dynamic column names. I have below code:

 

Set ti = Project.Variables.VariableByName("MyTable") 
ti.AddColumn("Name")

ti.RowCount = 1

Project.Variables.VariableByName("MyTable").Name(0) = "ABCD"

 

instead of passing "Name", I need to pass variable, like below

colName = "Name"

ti.AddColumn(colName)

Project.Variables.VariableByName("MyTable").colName(0) = "ABCD"

 

Above code returns "undefined" error.

5 REPLIES 5
tristaanogre
Esteemed Contributor

The reason being is that colName needs to be evaluated.  "colName" is not the name of the column so you can't set the value.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
cunderw
Community Hero

You want to use the item property of the table variable to get it by name.

 

See https://support.smartbear.com/testcomplete/docs/reference/program-objects/tablevariable/item.html


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
shankar_r
Community Hero

I don't think you can update/rename the existing column name.

 

Is there any reason why would you rename the Column?


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

@shankar_r I don't think he wants to rename after it's created, but have a way to create the table without a specified name. 


Thanks,
Carson

Click the Accept as Solution button if my answer has helped

Thanks guys for your response. I am creating table on fly and need to use column name as per the passed argument. I am able to resolve the issue now.

 

Thanks.

cancel
Showing results for 
Search instead for 
Did you mean: