Example Code

Convert Cluster to Array and Handle Each Data Type Differently

Code and Documents

Attachment

Download All

Overview
The attached ClusterToArray.vi example shows a method for handling each element of a cluster individually as an alternative to the Unbundle or Unbundle By Name functions. Unbundling very large clusters with many different data types can create complicated and visually challenging LabVIEW Block Diagrams with many wires. 


Description
This example provides an alternative that is cleaner and takes up less space on the Block Diagram. In the example, the cluster is converted to an array of controls via a property node. The values of each cluster element are then extracted individually in Variant form with an auto-indexing For Loop. The GetTypeInfo VI is then used to determine the LabVIEW Data Type of each element. (The GetTypeInfo and other VIs relating to Variants are located here: Program Files\National Instruments\LabVIEW 2011\vi.lib\Utility\VariantDataType). Finally, a case structure and the Variant To Data function are used to handle each element differently based on its LabVIEW Data Type. In the case of the attached example, String, Boolean, Double Float, and Array data are each displayed as their distinct data type. Running this VI requires LabVIEW 2011 or later. The Block Diagram is shown below.


Requirements

  • LabVIEW 2012(or compatible)


Steps to Implement or Execute Code

  1. Download the attached file to your computer
  2. Open the VI " Cluster To Array 2012 NIVerified.vi"
  3. Run the program

 

Additional Information or References
VI Block Diagram

BD.png 

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

Matt
NI Community Team
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.