01-15-2010 08:21 AM
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
Solved! Go to Solution.
01-18-2010 05:17 PM
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.
01-19-2010 03:40 AM
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?
01-21-2010 01:46 AM - edited 01-21-2010 01:46 AM
01-21-2010 03:57 AM
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?
01-21-2010 10:58 AM
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.
01-22-2010 01:27 AM
01-22-2010 03:15 AM
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
01-22-2010 05:35 AM
01-22-2010 08:09 AM
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.
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.