NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

copy container values with variable names determined at run-time

Solved!
Go to solution

I want to copy the contents of one container to another.  If I know the names of the container properties ahead of time, I can just use a statement saying such as

 

Locals.Container2 = Locals.Container1 

 

But if the names of the properties are to be determined at runtime, how do I do it?  If I were copying two numbers, I could do something like this:

 

Locals.asPropertyObject.SetValNumber("Number2", 0, Locals.asPropertyObject.GetValNumber("Number1", 0))

 

To copy containers, I would expect that I could use a similar statement using SetValVariant() and GetValVariant():

 

Locals.asPropertyObject.SetValVariant("Container2", 0, Locals.asPropertyObject.GetValVariant("Container1", 0))

 

But GetValVariant() causes an error ("Specified value does not have the expected type").  I don't understand why, though; probably because there is no variant data type in TestStand. (SetValVariant() works with no errors, however).

 

What would be the recommended way to do this?

 

0 Kudos
Message 1 of 7
(5,227 Views)

Hi jsiegel,

 

I think I understand what you are describing here. Just for clarification purpose, could you elaborate on how you are creating the containers? I'm going to have to do a little of homework on this one.

 

In the meantime, I've included the help file link for SetValVariant below.

 

http://zone.ni.com/reference/en-XX/help/370052J-01/tsapiref/reftopics/propertyobject_getvalvariant_m...

 

Regards,

 

Josh L.

Applications Engineer
National Instruments
0 Kudos
Message 2 of 7
(5,184 Views)

I am creating the containers (as a subproperty of the Execution container and also as a subproperty of a Local) using the PropertyObject.InsertSubProperty.  But I think that how the containers are created shouldn't make a difference--I would have the same problem even if I created the containers statically (i.e., at edit time) as Locals (for example).

0 Kudos
Message 3 of 7
(5,180 Views)

Hi.

 

Have you thought about getting the variable 'names' of the items in your cluster?  I create a cluster called 'One' it contains a  variable called 'number' and a string called 'string'.  You could use the 'GetNthSubProperty' function to get references to these objects and then obtain their names.  Then you could use the expression you stated before to set the number of the 1st cluster to the 2nd cluster once you know the variable names.

 

See attached. 

 

Thanks,

PH

 

0 Kudos
Message 4 of 7
(5,163 Views)

PH,

 

I understand I could get each subproperty one-by-one, but that's what I am trying to avoid--I'd like to set the contents of one container to the other by just referring to the container names.  If the container contents are complex (e.g., deeply nested), getting/setting each element separately gets tedious (and much less generic).

0 Kudos
Message 5 of 7
(5,146 Views)
Solution
Accepted by topic author jsiegel

How about something like:

 

Evaluate("Locals." + Locals.TargetName + " = Locals." + Locals.SourceName)

Message 6 of 7
(5,134 Views)

James,

 

That's perfect!  Thanks!

 

It still is a workaround for what seems like a missing more straightforward function.  But it achieves the goal.

0 Kudos
Message 7 of 7
(5,123 Views)