Accessing Properties and Methods of Array Elements

Updated Oct 1, 2018

Reported In

Software

  • LabVIEW Base
  • LabVIEW Professional
  • LabVIEW Full

Issue Details

I have an array of elements and I would like to programmatically change the properties or invoke methods of the elements. How do I get a reference to the elements in the array?

Solution

You cannot change the properties of individual elements in an array. All of the elements will always have the same property setting. For example, if you have an array of Boolean buttons and you set the color of the Boolean to blue, all of the buttons will be blue. To programmatically change properties or invoke methods for each elements in an array:
  1. Obtain a reference to the array of interest (To create a reference, right click on an array terminal from the block diagram and select Create»Reference
  2. Right click on the Array Reference, select Create>>Property for Array (strict) class»Array Element»Reference. Pass the array reference into a property node.
  3. At this point, LabVIEW doesn't know what the element type is, only that it is an element of an array. You need to tell LabVIEW the element type and this is done by using the To More Specific Class primitive located in the Application Control Palette. 
  4. Pass the Array Element Reference into the To More Specific Class primitive. Then create a reference of the type of interest. This can be done many ways. One way would be to place a Class Specifier Constant (found in the Application Control Palette) on the block diagram. Right click on the Target Class terminal and create a constant. Then select this constant and navigate to the type of interest. For example, if your array has elements of type string, then left click on the Class Specifier Constant and navigate to Generic»GObject»Control»String.  If not already wired, wire the Class Specifier Constant to the Target Class terminal of the To More Specific Class primitive. 
  5. Place a property node on the block diagram and wire the output of the To More Specific Class primitive to a property or invoke node. You now have access to the individual properties and methods available for that type.
The following VI snippet demonstrates how to use this method to programmatically access the font size of the elements in a string array:
 


"Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram."

WAS THIS ARTICLE HELPFUL?

Not Helpful