LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is It Possible To Get Array Size From An Array Reference?

Solved!
Go to solution

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.

davidpcl_0-1575456963012.png

 

Thanks is advance for any help.

David Clark
CLA | CTA
IDEX Biometrics UK Ltd
Hampshire, England
0 Kudos
Message 1 of 13
(3,122 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 2 of 13
(3,108 Views)
Solution
Accepted by topic author davidpcl

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.

Annotation 2019-12-04 123109.png


We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

Message 3 of 13
(3,104 Views)

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

David Clark
CLA | CTA
IDEX Biometrics UK Ltd
Hampshire, England
0 Kudos
Message 4 of 13
(3,088 Views)

Deleted answer. I did not read the post good enough so my answer was not relevant.

 

0 Kudos
Message 5 of 13
(3,065 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 13
(3,057 Views)
Solution
Accepted by topic author davidpcl

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.

array.png

Message 7 of 13
(3,011 Views)

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.

David Clark
CLA | CTA
IDEX Biometrics UK Ltd
Hampshire, England
0 Kudos
Message 8 of 13
(2,932 Views)

@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

Antoine Chalons

0 Kudos
Message 9 of 13
(2,917 Views)

@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.

Message 10 of 13
(2,889 Views)