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

If an array control reference is passed to a sub-vi, how do I obtain the current length of the array within the sub-vi?  I've tried two properties:  "NumRows", which as documented, contains the visible number of rows in the array control.  "IndexVals" contain the indices of the array element in the upper left corner of the array control.  There seem to be no methods for obtaining the current array length.  I tried changing the class of the array reference to cluster then using the "Controls[]" property... but this generated a runtime error.  What am I missing?  Thanks.

 

0 Kudos
Message 1 of 22
(5,104 Views)

Hi,

 

You can use the Value property node and then take the array size of the array.

ARraySize.JPG


Regards,

Nitz

(Give Kudos to Good Answers, Mark it as a Solution if your problem is Solved:smileywink:) 

0 Kudos
Message 2 of 22
(5,095 Views)

Thanks for your quick response.  This works on the front panel... but within the sub-vi, it's a different story.  Any further ideas?

 

 

0 Kudos
Message 3 of 22
(5,077 Views)

There's a lot of casting going on in your subvi.

 

What is the actual use case?  There might be a way to do this which doesn't require the casting and you could work just with the reference that is passed in.

 

For your method you need to wire in a strict class specifier into the To More Specific Class conversion.  I'm not sure how to make the strict class specifier.

0 Kudos
Message 4 of 22
(5,070 Views)

@acfkt wrote:

Thanks for your quick response.  This works on the front panel... but within the sub-vi, it's a different story.  Any further ideas?

 

 

Use Varient to Data with type = array of (whatever the array really contains) 

"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 22
(5,063 Views)

Thank you.  I don't know how to wire one in either, but it is a new line of investigation for me.

 

Yes, this .vi is general.  Certainly if the generality could go away, then the problem would go away.  Here is what the generality is providing.  At higher levels within the application, there is an array of device channel specific "meta-data" which will be read/written from/to a remote device.  Implementation wise, each row in the array is a collection.  The labels of the elements within the collection ARE the names associated with the meta-data passed to the channels on the remote device.  So new meta-data can be added, or names can be changed simply by changing the high level array of collections.  As there are several users of the device... and they have different, and mutable meta-data requirements, I decided to build a way to accommodate the changing requirements with minimum of programming.  Now each user can have their own meta-data interface to the device, but I don't have to change any underlying code... only make visible the appropriate array to the appropriate user.

 

The excerpt you are seeing, must match an actual physical device channel with associated meta-data in the array.  The array MUST have an element in the collection labeled "ch" so that matching can occur.  But that is the only requirement.  The .vi containing the excerpt is the meta-data manager for this project.  It has to operate on other controls which contain global meta-data to be written to all channels.

 

I think, this information is all a side issue to the kernel question:  How do I find the length of an array given a reference argument to a sub-vi?

 

Thanks for your time.

0 Kudos
Message 6 of 22
(5,057 Views)

@Taki1999 wrote:

There's a lot of casting going on in your subvi.

 

What is the actual use case?  There might be a way to do this which doesn't require the casting and you could work just with the reference that is passed in.

 

For your method you need to wire in a strict class specifier into the To More Specific Class conversion.  I'm not sure how to make the strict class specifier.


 

I can help with that but first...

 

Working with arrays on unknown data types is no esy task and determining the size is a special challenge and I did just that in this Nugget that talks about using control references. This task is much easier when you know at development time what is in the array. That is where the strict type casting comes into play.

 

What I would do...

 

1) Make sure the contents of the array is a type def (to support data strcuture changes in the future).

2) Go to the FP of the VI that has the array in question and drop a generic control ref control.

3) Ctrl-copy and drag the array in question INTO the the generic ref (still working on the FP). You can tell when you find the "sweet spot" in the ref control because it will switch it appearence. See this mini-nugget for an image where the same thing can be done with que refs.

4) Make the now strict ref a type def.

5) Use the type-def'd ref from step #4 in the sub-VI as the proptype used by the "To More Specific...."

 

After those changes you should be able to work with array in the sub-VI as if it were in the top level.

 

BTW:

Doing the above on the control in the sub-VI that brings in the ref would allow skipping the "To more Specific..."

 

Have fun!

 

Ben

 

 

 

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

Jeff, thanks for your response.  Well, I was trying to avoid that kind of hard coding.

0 Kudos
Message 8 of 22
(5,051 Views)

I think I see your problem.  You know only that the referance is to a control that is an array but the data in the arrar is only determined at run time and may change.

 

So, you have a generic array.  This, of course, has no size since it only has properties common to any array.  You need something to pass into this vi that will tell you about the type of data in the control so you can cast the array referance to the correct type def (And as Ben suggests- type def the arrays this vi can handle)

 

(And here's where I don't know enough about scripting) Array element style ID may be a helper


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 22
(5,049 Views)

@acfkt wrote:

Thank you.  I don't know how to wire one in either, but it is a new line of investigation for me.

 

Yes, this .vi is general.  Certainly if the generality could go away, then the problem would go away.  Here is what the generality is providing.  At higher levels within the application, there is an array of device channel specific "meta-data" which will be read/written from/to a remote device.  Implementation wise, each row in the array is a collection.  The labels of the elements within the collection ARE the names associated with the meta-data passed to the channels on the remote device.  So new meta-data can be added, or names can be changed simply by changing the high level array of collections.  As there are several users of the device... and they have different, and mutable meta-data requirements, I decided to build a way to accommodate the changing requirements with minimum of programming.  Now each user can have their own meta-data interface to the device, but I don't have to change any underlying code... only make visible the appropriate array to the appropriate user.

 

The excerpt you are seeing, must match an actual physical device channel with associated meta-data in the array.  The array MUST have an element in the collection labeled "ch" so that matching can occur.  But that is the only requirement.  The .vi containing the excerpt is the meta-data manager for this project.  It has to operate on other controls which contain global meta-data to be written to all channels.

 

I think, this information is all a side issue to the kernel question:  How do I find the length of an array given a reference argument to a sub-vi?

 

Thanks for your time.


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.

 

*EDIT: Both Jeff and Ben got in better and more informative answers while I was thinking and posting *

0 Kudos
Message 10 of 22
(5,046 Views)