LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Brick Wall Problem: Array of Clusters, Size of array from reference

Solved!
Go to solution

Good Morning Forums,

 

I have hit a brick wall with my application and I am hoping somebody can help!

 

I have an array of clusters of indeterminate size (the cluster is generic, data contained not relevant.).

 

Inputs to the VI are: a reference to the array, and a variant containing the data.

 

My problem is I need to determine the array size from these two inputs and I cannot find a way to do it!

 

If the array contained a standard data type I can use the class name property to determine data type, and the size of the array returned from "select size" property to determine dimension size.  With this information i can cast the variant into the correct data type and use this to determine the size of the array.  If the data is a cluster the class name simply returns "cluster" so I cannot cast the variant and therefore am unable to determine the size.

 

I am not worried about casting the data (once i determine the size this bit is no issue), I just need to determine the size (and preferably number of dimensions) of the array. Can this be done?

 

Cheers for any help

J

------
John.P | Certified LabVIEW Architect | NI Alliance Member
0 Kudos
Message 1 of 6
(4,111 Views)

There's an OpenG VI that gets the # of array dimensions from checking the bits in the Type Descriptor output out variant to flattened string.  Look in the VData package.

-Barrett
CLD
0 Kudos
Message 2 of 6
(4,095 Views)
Solution
Accepted by topic author John.P

Use "Variant to data to change" the variant to an array of variants and take the size of that.

21445i1A71A65C8B5F4D64

Edit.

Opps missed the variable number of dimensions requirement, in that case you want "Array Size(s)" from OpenG like blawson mentioned.

Message 3 of 6
(4,090 Views)

 


@John.P wrote:

Good Morning Forums,

 

.

 

I am not worried about casting the data (once i determine the size this bit is no issue), I just need to determine the size (and preferably number of dimensions) of the array. Can this be done?

 

Cheers for any help

J


 

There seem to be a couple of potential solutions.:

#1 if the varient is created within LabVIEW you can wite size(s) to a varient attribute.  This would be pretty straightforward and easy to implement- I imagine you would have thought of that so you may not have access to the code writing cluster to varient and it gets a bit trickier.

#2 cast the varient to string and return string length-  this should give you a measure of total size and you would need to know the size per element of cluster (just cast one instance of cluster array to varient and then to string with size and size++) but this only returns the total size of the array since nDim arrays are actually stored sequentially. 

 

Hope this helped


"Should be" isn't "Is" -Jay
Message 4 of 6
(4,069 Views)

Cheers for the replies guys.

 

blawson, I wasn't aware of the OpenG VI but need to keep the code all standard LV as it will be used by people who will only have standard LV.

 

Matt, this was the best way to do what I wanted, casting the variant to an array of variants will give you the size of the array no matter what the array contains, and I could still use the "select size" property to determine number of dimensions.

 

Jeff, Thanks for the input, I had thought about variant attributes but as you rightly guessed I cannot implement this into the code that converts the cluster to a variant in the first place!  Your second suggestion could work but require more code than Matts suggestions.

 

Thanks again.

J

------
John.P | Certified LabVIEW Architect | NI Alliance Member
0 Kudos
Message 5 of 6
(4,054 Views)

I use the GetArrayInfo.vi from vi.lib myself.

 

21449iDF7D19D903CE5DF8

Message 6 of 6
(4,049 Views)