Example Code

Detachable Run Button - A XControl Example

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

Overview: This example uses the power of an XControl to create a detachable Run Button.


Description: 

When placed on the Front Panel of any VI, the control will replace the VI's existing Run button and run the owning VI when clicked.

To try this out on your own, simply unzip the attached files, open up the project and the 'Tester.vi' and then click the run button on the front panel to run the VI.  If you would like this functionality on one of your own VIs, simply click and drag the included XControl onto your Front Panel.


Requirements: LabVIEW 2012 (or compatible), Hardware: none.


Steps to Implement or Execute Code:

1. Run the VI, clicking the Arrow.
2. If you would like this functionality on one of your own VIs, simply click and drag the included XControl onto your Front Panel.

 

Alternate steps: this functionality is surprising easy to implement on your own.

1. Create a new XControl.

2. Add code to the Init.vi to hide the control label, resize the control to a suitable size, and hide the owner VI's Run Button.

3. Next, add a boolean control to your Facade.vi and give it the appearance of your chosing.  (You might want to use the Advanced>>Customize functionality.)

4. Then, add a Value Change event for that boolean and use the refnum in the Container State control to programmatically run the Owner VI when the value change occurs.  This works because the Value Change event will fire even if the Owner VI is not running.

5. I also added code to the Exec State Change case to show or hide the control depending on the state of the Owner VI.


Additional Information or References: 

 

Detachable Run Button - A XControl Example FP.png

 

Detachable Run Button - A XControl Example sn.png


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

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