NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Find an Array Element by Name

Hi All,

 

We have been assigning names to the Name property of each element of an array of containers.  The containers themselves have just two sub-properties; a string and a bool.  We would like in our sequence to pass a string parameter in and and see if it matches the Name property of any elements in the array.  We know we can iterate over the array of containers each time we need to do this check, but that feels clunky and that there is likely a more elegant method available.

 

The reasons we would like to do this is the string property of each item in the array holds a NI CompactDAQ Digital Line string for a line we would like to control and the Name property given to the array elements allow us to provide a more meaningful name.

 

Any support on this would be much appreciated.

 

Regards

 

John

0 Kudos
Message 1 of 5
(195 Views)

Hi John,

 

I am not aware of an "un-clunky" way to achieve this in TS, yet I would be happy to learn!

 

Basically, you need something like a dictionary... 

 

  • If you are the LabVIEW guy, create an FGV holding a Map 
  • If you are a .net guy, create a dictionary

 

0 Kudos
Message 2 of 5
(189 Views)

Hi Oli_Wachno,

 

Thanks for your quick response.  It seems we can achieve our intention within a TestStand statement step using the PropertyObject.Exists method.  All we needed to do was properly form the lookup string so it included the brackets and quotes, such as "[\"" + locals.lookupStr + "\"]".  Such as: -

 

Locals.ItemFound = Locals.MyArray.Exists("[\"" + Locals.ItemToFind + "\"]", 0)

 

This seems to be a more concise method.

 

John

Message 3 of 5
(173 Views)

Thanks for sharing this solution!

 

 

 

 

0 Kudos
Message 4 of 5
(168 Views)

Glad to find and offer it.

0 Kudos
Message 5 of 5
(164 Views)