NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

how to creating a dynamic array during execution

Hi,

i had created a seven packets and send it in TCP as a single request,then i got a seperate response for that query.Now i want to create a dynamic array for that responses as a single array......how can i do that during execution of the program....... 

0 Kudos
Message 1 of 4
(6,270 Views)

Hey sowmipriya,

 

You can use the TestStand API to create new variables. Creating an array is a little different than most other types, and can be done as follows. You could put this in a Statement step, or as a pre or post expression of a step:

 

Locals.NewSubProperty("MyArray",PropValType_Number,True,"",1)

 

This expression accesses the Locals container and adds a new property called MyArray. The type of that array is a number (when you type this in TestStand you'll get a drop-down of types). Note that once this array is created, it will have zero elements. Now we need to dynamically size it, as you requested.

 

First, here's a TestStand Help document on dynamically resizing arrays. Basically, we just need to access the array object and set the number of elements. Here's an example:

 

Locals.GetPropertyObject("MyArray",0).SetNumElements(3,0)

 

That accesses our array and sets the number of elements to 3. Also, note that we can put both of these expressions in the same expression field by putting a comma between them....so expression 1, expression 2.

 

 

As a side note, if you create the Local variable itself during execution (our first expression), it will not be visible at edit time. So if you write later expressions in your program which use that variable, TestStand will tell you that it thinks the syntax is incorrect because it doesn't recognize the variable. I'd recommend creating the variable with the graphical interface in the Variables pane, and then just using the second expression to dynamically resize the array once you know how many elements it needs.

 

Hope that helps, and let us know if you have any more questions!

Message 2 of 4
(6,260 Views)

Thanks a lot I will try on this...

0 Kudos
Message 3 of 4
(6,249 Views)

Hi Daniel,

 

Thanks for the explanation, however I have an additional challenge.

So this dynamically created array can be accessed with "Locals.MyArray", although TestStand will complain that it does not recognize it.  However, what if the name of MyArray, is also set dynamically such as set by the programmer through a parameter. Since the name of the Array vairaible is not yet known, hoe would I access this array, for example to intitialize it.  Would I use "Local.(Paramater.ArrayName)?

0 Kudos
Message 4 of 4
(4,824 Views)