LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array size from refnum

Is it possible to get the size of an array when all I have is a refnum to the array control. I know I can get the value and pass it through the 'array size' function. However, this requires me to cast the type of value from a variant to whatever the type of the array is, and I would prefer not to do that.

The code in question is implementing binding a slide control to an array control to act as a scrollbar for the array. With the exception of this one problem, I was able to implement it entirely independant of the type of the array. Since I will be using this functionality for several arrays holding different things, I would like to keep it that way.

Can I cast the varient using only data in the propery node, such as class ID? Is there ano
ther way to get the size of an array that does not involve casting? Any other ideas?
0 Kudos
Message 1 of 7
(3,561 Views)
The only way to do this (without converting to original datatype) is very inefficient. You use "Variant to Flattened String" function on the variant "Value" property of the array refnum. The array size is the first four bytes of the flattened string so typecast the string to a U32. This is inefficient because it requires to copy and flatten the whole array just to read its size. I wish there were an array property for this. If the array has more than 1D, the sizes for each dimension are stored consecutively at the beginning of the flattened string.


LabVIEW, C'est LabVIEW

Message 2 of 7
(3,561 Views)
Hi Jackson,
I'd suggest you to download the free OpenG Toolkit here: http://www.openg.org/; among a huge amount of very useful functions you can find Array Size(s).vi that returns the size of an array of any type.
Good luck,
Alberto
Message 3 of 7
(3,561 Views)
Hi,
Yes I've looked at OpenG and it appears to be fairly usefull. Unfortunately, my employer will only allow GPL'd code in rare cases, and the the review process to get permision to do so is too involved for something small like this. Therefore, it would really be best if I didn't even look at how OpenG implements this functionality, to be safe.
0 Kudos
Message 4 of 7
(3,561 Views)
Funny...

I got 3*s to have explained you how to get the array size from a variant the way I did implement it in OpenG tools and Alberto got 4*s to pointing the tool in OpenG.org :-)) (thanks Alberto)

Seriously, do it the way I explained in my first answer: simply Flatten the variant to string and extract the size from the first 4 bytes of the string.


LabVIEW, C'est LabVIEW

0 Kudos
Message 5 of 7
(3,561 Views)
Hi Jean-Pierre,
actually I thank you and Jim Kring for the effort you put in developing the mentioned toolkit!
Alberto
0 Kudos
Message 6 of 7
(3,561 Views)
Thanks! I should only have to do get the size once anyway so your solution will work very well.
0 Kudos
Message 7 of 7
(3,561 Views)