Example Code

Array to Variable-Sized Cluster

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Overview
This example demonstrates how to set the visibility of each element in the cluster so that the number of elements displayed matches the number of items in the original array
Description

Here is a brief description of the example:

With the Array to Cluster function, it is possible to convert an array of data to a cluster of those same elements.  Unlike the array, the cluster has a fixed size configured through the right-click menu of the Array to Cluster function. Thus, if the array size is not known at run-time, the cluster may display too many or too few elements.

This VI sets the visibility of each element in the cluster so that the number of elements displayed matches the number of items in the original array.

 

Requirements

  1. LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Enter the number of elements to create (maximum of 20) and run the VI.
  2. Repeat with a larger or smaller number and notice that the number of elements displayed in the cluster changes accordingly.

 

Additional Information or References
VI Snippet

Dynamic Cluster 2012 NIVerified.png 

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

Jennifer R.
National Instruments
Applications Engineer

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

Comments
MattI
Member
Member
on

The example gives a nice solution to the difficult problems that can be encountered when writing a semi-scalable user interface.

For example, when you want to create a list of items with select boxes, but sometimes not have them be selectable by users (because they are N/A -- meaning not applicable or not available).

One example of this would be if you want to notify a list of users by email of an event.  Let's say this list is built dynamically by reading in an external file, so using an array is good for the unknown & possibly changing size of this list.  However, another aspect of this list is that some users do not have a secondary email.

Using an array initially seems like a nice way to couple user names and primary + secondary email Y/N selection buttons.  However, if the user doesn't have a secondary email listed, no selection should be enabled for it.

This can't be done on a per-user basis using an array; properties for the controls that are within clusters (the array element is a cluster) apply to every element of they array.

If a cluster of clusters is used instead of any array of clusters, it can be made to look like an array and even "act like" an array; after all, an array has a finite display size. The cluster can be made to look/work very much like an array, with a numeric control that looks like and works like the array index, but in this case it will be a cluster display start index.  (Similar to the example, I wired the result of an "in range?" boolean to the Visible property node.  I've tried it out & it works fine.)

AustinManinTown
Active Participant
Active Participant
on

The screen shot (VI Snippet) should not be saved, as it does not work. It really should be updated. The attached VIs do work correctly.

David C