LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Given array control reference, how do I obtain array size programatically

Solved!
Go to solution

@Taki1999 wrote:
...I think Jeff's method will work well if you know what the datatype of your array is.

It may just shift the question from "How do I find the length of an array given a Generic reference?" to "How do I find the datatype of an array given a Generic reference?"

 

Unfortunately, I don't think I know the answer to either.


 

Answer:

 

Poke at it until it stops screaming. See the nugget I linked above.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 11 of 22
(2,810 Views)

Thank you Ben, reading nugget now.

0 Kudos
Message 12 of 22
(2,809 Views)
Solution
Accepted by acfkt

If the reference will always be to 1-D array (or perhaps as long as the number of dimensions is always the same), there's an easy way to do this.  You can use "Variant to Data" to convert a Variant (that contains an array) to an Array of Variants, and then use Array Size:

size of generic array.png

Message 13 of 22
(2,802 Views)

@nathand wrote:

If the reference will always be to 1-D array (or perhaps as long as the number of dimensions is always the same), there's an easy way to do this.  You can use "Variant to Data" to convert a Variant (that contains an array) to an Array of Variants, and then use Array Size:

size of generic array.png


Yeper!

 

The more we know about the data the easier it gets.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 14 of 22
(2,791 Views)

Probably worth noting as well that you can get the array dimensions from the control reference by getting the Value property (as a variant) and feeding it to GetArrayInfo in the VariantDataType library (vi.lib\utility\VariantDataType).  That VI also has an output called "Array Lengths" but unfortunately it doesn't actually get you what you want, since it returns that the array lengths are variable.  It will only return real values for fixed-length arrays such as used in FPGA, or bounded arrays (no idea when they're used in LabVIEW).

Message 15 of 22
(2,789 Views)

With an assist from vi.lib:

 

ArraySizes.png

 

..\vi.lib\Utility\VariantDataType\GetArrayInfo.vi

 

(I actually only have used this for finding NDims, never bothered unbundling the Lengths).

Message 16 of 22
(2,787 Views)

Just beat me to it

BH.png

 

  WRT. Yair


"Should be" isn't "Is" -Jay
0 Kudos
Message 17 of 22
(2,781 Views)

@Darin.K wrote:

 

(I actually only have used this for finding NDims, never bothered unbundling the Lengths).


Unfortunately, as I noted just a minute before your post, this doesn't work for finding array lengths.  Each dimension gets a length of "Variable" and 0.

0 Kudos
Message 18 of 22
(2,776 Views)

@nathand wrote:

@Darin.K wrote:

 

(I actually only have used this for finding NDims, never bothered unbundling the Lengths).


Unfortunately, as I noted just a minute before your post, this doesn't work for finding array lengths.  Each dimension gets a length of "Variable" and 0.


Glad I never tried to use it in that fashion.  In scripting (such as a QD shortcut) I find myself with an array reference and some data to copy or paste so I only care about the dimensions.  In this case we could join forces:

 

ArraySizes_v2.png

 

Message 19 of 22
(2,769 Views)

This is just a hazy suggestion from times long past, but I believe you might be able to use the type cast primitive to cast the variant to an array of variants (or 2D array of variants) and then use the normal array size primitive to get the length.

0 Kudos
Message 20 of 22
(2,764 Views)