06-11-2011 02:40 PM
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?
Solved! Go to Solution.
06-13-2011 09:29 PM
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.
Regards,
Josh L.
06-13-2011 11:31 PM
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).
06-14-2011 01:04 PM
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
06-15-2011 01:36 AM
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).
06-15-2011 10:37 AM
How about something like:
Evaluate("Locals." + Locals.TargetName + " = Locals." + Locals.SourceName)
06-16-2011 01:03 AM
James,
That's perfect! Thanks!
It still is a workaround for what seems like a missing more straightforward function. But it achieves the goal.