04-14-2012 11:40 PM
I have created a container which contains numbers and strings elements. I would like to pass the element one by one to a vi. But I don't know how to extract the element respectively.
Is there a way to get the container's element one by one? Something like: Array[1], Array[i+1] will simply work for array, but what about container? I can't do Container[i]. It will return error.
Thanks a lot in advance!
Solved! Go to Solution.
04-16-2012 02:57 AM
There are two options :
You can use an array of containers and use container[i].x
Other option is to create array of elments within a container .
Then you can use container.num[i] or container.str[i] to get the values.
Hope this helps.
04-16-2012 03:30 AM
Yes I can use array of containers and use container[i].x But how do I specify "x"? Can I use a loop index to stand for x then traverse all elements in a loop?
04-16-2012 06:08 AM
Sorry i did not get your question correctly.
You want to read the elements within a container.
Please do the following : ( container name = cont)
Locals.num=RunState.Main.Locals.GetNumSubProperties("cont") --- This gets the number of elements in your container
With this you can start a for loop for n sub elements.
In this loop - To get the each element name of the container use this :
Locals.str=RunState.Main.Locals.GetNthSubPropertyName("cont",Locals.i,0)
You can concat "cont." and locals.str to get the sub element name
Use this to get the value directly i.e. locals.x = cont.name
Hope this helps.
04-20-2012 01:21 AM
Hi
By using your way I get the correct element number and element name. That's a great help. Thanks a lot!
But regarding the element value you were saying to use "locals.x = cont.name". The problem is that the name I get from "GetNthSubPropertyName" is a string. Then if I pass cont.name into locals.x, locals.x gets the string value "cont.name" rather than the real value of the container's element. It could be, in my case, a number or a string.
Is there a kind of function like "GetNthSubPropertyValue" which could obtain the value of a local container, or do you have another way of achieving this?
04-20-2012 03:59 AM
Once you get container.element_name in a variable example : locals.tempstr ="cont.str1"
Use the below function to get the value.
Locals.str=RunState.main.Locals.GetValVariant(Locals.tempstr,0)
This works for both number and string - chosen variant for that purpose.
For numeric values you can use val(locals.str) to convert back to the numeric type.
There should be a way to get the type of variable.Will explore further and let you know.
Hope this helps.
04-28-2012 12:52 AM
Super! that one also works. Thanks a lot!
10-27-2020 10:10 AM
I am trying to access Array of Containers....How can I do that?
10-27-2020 10:40 AM
Never mind...I used following step to do that -
Locals.Value == RunState.Main.FileGlobals.GetValNumber("Name_Of_Array["+Str(index_value)+"]"+"Container_Name")
But please let me know if there is any other way...