NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to combine elements to container in expressions?

Solved!
Go to solution

Hi, dear ALL

 

We can combine elements into array via curly braces. For example: Locals.arrayOfStrings = {"Hello", "World"}

 

My question is - could we combine elements into container?

 

Thanks in advance,

Max

0 Kudos
Message 1 of 14
(4,874 Views)

Hi Max,

 

You cannot use the curly brace format to combine elements togehter into a container; this notation will only work with arrays.  You can alter elements in a container by using the dot notation (e.g. MyContainer.Parameter1 = x).  You can also assign one container to another, but the fields need to be of the same type and name.

Cheers,
Kelly R.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 14
(4,839 Views)

Thank you, Kelly. In that case could you help me find the best solution for such a problem -

 

For example, we have a container 'cluster'. It consists of two fields named 'field1' and 'field2'. Now I want to create an array of 'cluster's with 10 elements - 'arrayOfClusters'. The brute solution will be -

 

SetNumElements(arrayOfClusters,10),

arrayOfClusters[0].cluster.field1 = "bla-bla-bla"

arrayOfClusters[0].cluster.field2 = "bla-bla"

...

 

And if the 'cluster' is not a container but, for example, a simple string, then we can do so:

arrayOfClusters = {"bla-bla-bla", "bla"} + {"bla-bla"}

In other words - we can define an array without a need to use SetNumElements function.

 

Is it possible to define an array of containers without SetNumElements?

0 Kudos
Message 3 of 14
(4,825 Views)

Hi,

 

I have played with custom data Types

Maybe this works for you

 

juergen

 

 

Message Edited by j_dodek on 01-21-2010 08:46 AM
--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 4 of 14
(4,795 Views)

Hi, Juergen. Thanx for your code, but it doesn't suite. This is because of my bad explanation, maybe..

 

Nevertheless, the key feature I want to investigate is an implicit increase of array's size. In case of array of strings, for example, this feature can be implemented like:

 

// initially Locals.array is empty

Locals.array = {"first", "second"} + {"third"}

// now Locals.array size is 3

 

And in case of array of containers, this feature seems to be unavailable =( And we have to explicitly increase array size via SetNumElements. Am I right?

0 Kudos
Message 5 of 14
(4,792 Views)
Solution
Accepted by maksya

Hi Max,


There are two options that you can try here.  I would take a look at both methods and see which works best for your application.

 

For the first method, you will need to have pre-defined clusters.  You can then combine these clusters together into an array.  The format for this method is"

 

Locals.MyArray = {Locals.MyContainer1. Locals.MyContainer2} + {Locals.MyContainer3}

 

The second option will use an array of arrays instead of an array of containers, but you will achieve the same functionality.  You can create a blank  local variable (array of containers), and then execute the followign statement:

 

Locals.MyArray = {{1, "test"}, { 2, "test"}}+{{5, "world"}}

 

The results of both of these methods are attached.  I think from your previous posts that this is what you are looking to do.  You can see, we started wtih an empty array of containers, and in neither case did we need to use  SetNumElements.

Cheers,
Kelly R.
Applications Engineer
National Instruments
Download All
Message 6 of 14
(4,775 Views)

Hi Kelly,

 

just some questions on filling literal.

Please see attached file

 

juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 7 of 14
(4,759 Views)

Hi Juergen,

 

Maybe its because both elements are strings that it treats as array of string.

What happens when both are not strings eg 

Locals.MyArray = {{1, "test"}, { 2, "test"}}+{{5, "world"}}

 

Regards

Ray

 

 

Regards
Ray Farmer
0 Kudos
Message 8 of 14
(4,745 Views)
Hi Ray, It will insert an array of container. Still wondering why this is allowed and even working. I am expecting an Error like this: "You a can not copy a Container in an array of Type 'cluster' " Juergen
--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 9 of 14
(4,737 Views)

TestStand does not restrict type of the elements within an array of containers. The type container is not specific in that you can have a container that has one field or multiple fields, the fields can be all of the same type or of different types. So, an array of containers can contain elements of any type.

 

arrayOfContainersForum.png

 

Juergen - in your example, you've created a custom data type named "cluster", however, "cluster" is still a container, thus an array of "clusters" is, underneath the hood, an array of containers and can thus contain elements of any type.

 

Hope this helps.

Manooch H.
National Instruments
Message 10 of 14
(4,726 Views)