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.
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.
12-09-2011 11:46 AM
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.
Solved! Go to Solution.
12-09-2011 01:14 PM
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
12-09-2011 01:19 PM
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?
12-09-2011 01:38 PM
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