12-04-2019 05:04 AM
Does anyone know if it's possible to get the number of elements in an array from a reference to an array?
Either I have found that something that has completely stumped me (or I'm missing something really obvious), or it isn't possible.
The code snippet below shows a small test harness I've setup. I have a reference to an array of clusters, I'm casting to a generic array, to simulate handling different array content types, and then I'm indexing an array element (referencing this post https://forums.ni.com/t5/LabVIEW/Reference-to-array-element/td-p/737720?profile.language=en).
However, for what I'm trying to do, I need to know the size of the array, and at present I can't see from the array properties available that it is possible, and other techniques like seeing if the property node throws an error for an out of bounds index doesn't work.
Thanks is advance for any help.
Solved! Go to Solution.
12-04-2019 05:30 AM
The reference isn't to the array, but to the control or indicator on the FP.
To get the size you'll need to Value property and use Array Size.
/Y
12-04-2019 05:32 AM
If you cast the array ref to a more generic as show in the picture, it gets a bit more difficult.
There is an OpenG VI to do it, I had a look inside and my eyes started to bleed.
We have two ears and one mouth so that we can listen twice as much as we speak.
Epictetus
12-04-2019 05:52 AM
Thank you both for your replies, that open G VI will do the job nicely, and it's not something I would have ever come up with as a solution myself.
And yes, my eyes are bleeding here too after looking inside that VI!!
Dave
12-04-2019 07:28 AM - edited 12-04-2019 07:30 AM
Deleted answer. I did not read the post good enough so my answer was not relevant.
12-04-2019 07:47 AM
I had to figure out the answer to that questions back in LabVIEW 8.2 (more than 12 years ago now!) when I first became bored with having to start from scratch to restore arbitrary configuration data structures for the project I was writing.
I came up with this Nugget about how to exploit control references.
Soon there after MGI came up with their own version then OpenG and eventually NI added more operators to the Variant Parse Data type sub-palette that make things much more simply.
But for the sake of eye-bleeding, I invite you to review that Nugget.
Ben
12-04-2019 11:22 AM
If y'all don't want to use the scary OpenG VI, you can cast the array value to an array of variants, then get the size of that array.
12-05-2019 05:23 AM
The power and flexibility of variants never ceases to amaze me! It's a topic I really need to learn an awful lot more about. That's really useful. Thanks Darren.
12-05-2019 07:06 AM
@Darren wrote:
If y'all don't want to use the scary OpenG VI, you can cast the array value to an array of variants, then get the size of that array.
Green washing is so trendy these days
We have two ears and one mouth so that we can listen twice as much as we speak.
Epictetus
12-05-2019 09:59 AM
@TiTou wrote:Green washing is so trendy these days
With multiple references to "eye bleeding" in the thread, I wanted to let everybody know there was a simpler way.