04-24-2012 01:19 PM
@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
04-24-2012 01:19 PM
Thank you Ben, reading nugget now.
04-24-2012 01:37 PM
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:
04-24-2012 01:42 PM
@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:
Yeper!
The more we know about the data the easier it gets.
Ben
04-24-2012 01:48 PM
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).
04-24-2012 01:50 PM - edited 04-24-2012 01:52 PM
With an assist from vi.lib:
..\vi.lib\Utility\VariantDataType\GetArrayInfo.vi
(I actually only have used this for finding NDims, never bothered unbundling the Lengths).
04-24-2012 01:53 PM - edited 04-24-2012 01:54 PM
Just beat me to it
WRT. Yair
04-24-2012 01:56 PM
@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.
04-24-2012 02:03 PM
@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:
04-24-2012 02:19 PM
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.