Showing results for 
Search instead for 
Did you mean: 

Get element from container

Go to solution

Get element from container

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!

0 Kudos
Message 1 of 7

Re: Get element from container

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.

0 Kudos
Message 2 of 7

Re: Get element from container

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?

0 Kudos
Message 3 of 7

Re: Get element from container

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 :



You can concat "cont." and locals.str to get the sub element name

Use this to get the value directly i.e. locals.x =


Hope this helps.

0 Kudos
Message 4 of 7

Re: Get element from container


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 =". The problem is that the name I get from "GetNthSubPropertyName" is a string. Then if I pass into locals.x, locals.x gets the string value "" 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?

0 Kudos
Message 5 of 7
Accepted by topic author funin
08-27-2015 04:09 PM

Re: Get element from container



Once you get container.element_name in a variable example : locals.tempstr ="cont.str1"


Use the below function to get the value.




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.


0 Kudos
Message 6 of 7

Re: Get element from container

Super! that one also works. Thanks a lot!

0 Kudos
Message 7 of 7