From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

RemoveElements/InsertElements

Solved!
Go to solution

Is it just me or is it an abomination that a string parameter is passed for an array index? WTF?  I hope I'm missing something fundamental for why that must be like that.  Regardless, can you only pass parameters like "[0]" to this function or am I just not constructing the expression right to be able to insert or remove at a programmatically determined index?

 

I've tried various flavors of "[Str(Locals.Index_to_remove)]" but I don't have the syntax just right.

 

 

0 Kudos
Message 1 of 4
(3,931 Views)
Solution
Accepted by topic author CoastalLabVIEWER

You can use the PropertyObject Get\Set*ByOffset functions combined with the PropOption_InsertElement or PropOption_RemoveElement options to specify an array element by offset. It's pretty straightforward as long as you have a zero-based single-dimensional array. Don't forget, arrays can be multi-dimensional so a simple API with a single integer for the index would not work in such cases. The lookupstring for an array element of a multi-dimensional array is a bit more complicated than what you are doing (e.g. "[1][0][3]"). There is also the PropertyObject.DeleteElements() method which takes an offset.

 

That said, the expression you are looking for is:

"[" + Str(Locals.Index_to_remove) + "]"

 

-Doug

Message 2 of 4
(3,928 Views)

Thanks dug!

 

Having to handle multi dimensions is a decent reason for constructing a string.  However, wouldn't an array of numbers for the parameter be a bit more intuitive?

0 Kudos
Message 3 of 4
(3,924 Views)

For arrays of containers, array indices can actually be element names rather than indices, for example: ["myelementname"] is a valid index for an array of containers where one of the elements is named myelementname. Also lookupstrings can contain more than just indices, they can contain the full property path to the element, for example: "mysubprop1.mysubprop2.myarray[3]".

 

There could still have been special functions just for the case of indexing arrays using an array of integers. They could even potentially still be added as an additional API enhancement (Feel free to post such a suggestion to the idea exchange if you like). However, lookupstrings are more flexible and allow for more functionality.

 

Hope this helps explain things,

-Doug

0 Kudos
Message 4 of 4
(3,922 Views)