NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

using string names to refer to arrays

I want to be able to manipulate arrays of containers but the names of the arrays will vary so the system must be able to deal with this.
I have the current array name in a local variable.
how can I use this string to refer to the array of the same name?
 
for example:: Array name is "My_First_array"
 
the local variable Current_Array_Name = "My_First_array"
 
now I want to use a statement  to set the array size to 100
 

SetNumElements( Locals.Array_Name,100 )

as you can imagine this causes an error as it expects an array and not a string.
 
Does anyone know of a simple solution to this?
0 Kudos
Message 1 of 10
(5,239 Views)
SetNumElements(Evaluate("Locals." + Locals.Array_Name), 100)
Message 2 of 10
(5,235 Views)
Hi James.
thanks for that, I can now control the size of the array but how do I put data into an element of the named array?
I tried using the code
        Evaluate("Locals." + Locals.Array_Name)[0] = "Hello" but TestStand did not understand the expression
 
Is there a simple way to put data into such an array or must I use some activeX actions?
 
Thanks
 
Jimmy
0 Kudos
Message 3 of 10
(5,231 Views)
Hi,
Try using a ActiveX adapter, with the reference as Evaluate("Locals."+Locals.My_Named_Array[0]).
 
Call a PropertyObject.SetValStringByOffset(0,0,"Hello")
 
Hope this helps
Regards
Ray Farmer
Regards
Ray Farmer
Message 4 of 10
(5,218 Views)

Hi Jim,

  unfortunately I don't think you're going to acheive this as a statement.

The evaluate returns the item from the string, but since it translates to a string, that's what's being returned - the string, no the property object.

So you could do an activeX call on the TestStand API for a propertyobject from thiscontext as the object, and then a method SetValString.

The lookupString would then be

Evaluate("\"Locals.\"+ Locals.Name + \"[0]\" ")

that should handle it for you. (you could do this as a pre-expression if necessary and tack it into a local data space for convenience. The string is kind of complex, because you need the \"s to get the actual literal string that evaluate is using to translate to "Locals." + Locals.Name + "[0]"

Until there's a operator/function that converts a string to an object reference, then we'll have to stick with the ActiveX method.

Sorry.

Thanks

Sacha Emery
National Instruments (UK)

 

// it takes almost no time to rate an answer Smiley Wink
Message 5 of 10
(5,219 Views)

Hi Sasha

The real situation that I am working on is as follows which is a bit more complex:

The arrays that I am manipulating are arrays of containers similar to the locals.ResultList but they are stored in StationGlobals.Test_Cases

I can create the arrays and resize them now.

The local.Array_Name variable holds the value "StationGlobals.Test_Cases.Array_A"  where Array_A is the array that I created and resized.

the Local.X holds the current array index that I want to write data to

How complicated is it to add a single result cluster to a given element? can I do this in one step?

 

Again thanks to everyone for the assistance.

Jimmy

 

0 Kudos
Message 6 of 10
(5,202 Views)

Hi Jim,

  you'll need the correct property object to start with, i.e. the container that you want to put in place and then you can use SetValVariant from the property object.

The other option is to do it one field at a time, and adjust the lookup string appropriately.

I've attached an example using set val variant in TestStand 3.5 (I've just kept it all Local, but it should be quite easy to translate to your StationGlobals.)

Hope that helps

Thanks

Sacha Emery
National Instruments (UK)

// it takes almost no time to rate an answer Smiley Wink
Message 7 of 10
(5,187 Views)

Hi Sasha

That's exactly what I want to do. Thanks a million

Jimmy

0 Kudos
Message 8 of 10
(5,172 Views)

Following on from what I have learnt so far I now have the following problem.

I want to create an array of user defined containers. i.e. each element would be a cluster containing strings, numbers or anything else.

For this example I will call it MyContainerType.

I have tried to create an array of containers but when I try to add an element of MyContainerType I get an error message as follows

An error occurred calling 'SetValVariant' in 'PropertyObject' of 'NI TestStand API 3.1'
Variable or property types do not match or are not compatible.
Error accessing item 'StationGlobals.Test_Cases.My_test_step_100[0]'.

I am using the function NewSubProperty to create the empty array and setting the property value type to PropValType_Container

is there a better way to create an array of a user defined type?

Regards

Jimmy

 

 

0 Kudos
Message 9 of 10
(5,122 Views)

Hi Jim,

  hopefully this posting will give you the answers you need.

http://forums.ni.com/ni/board/message?board.id=330&message.id=10088#M10088

essentially I think you need SetPropertyObject, and not SetValVariant.

Hope that helps

Sacha Emery
National Instruments (UK)

Message Edited by SachaE on 03-27-2006 11:53 AM

// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 10 of 10
(5,090 Views)