Example Code

Method of Identifying what Control Triggered an Event Case

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

Description

Overview: This example shows how to identify which control triggered a particular event case that could be triggered by multiple different buttons.


 Description: In LabVIEW, the event structure can be used to execute certain code when an event occurs. In this example, a value change on different front panel objects (Button 1, Button 2, Numeric, Stop) cause the same case to execute in the event structure. This example shows how to determine which of these front panel objects was the source of the event.

 

In order to do so, you can use the CtlRef output  from the event structure's left Event Data Node. The CtlRef returns the reference that points to the control that was the source of this event. A property node can be used to access the label of the control which can then be displayed on the front panel.


Requirements: LabVIEW 2012 (or compatible).


Steps to Execute Code

  1. Run the VI.
  2. Change the values on various controls on the front panel and see that the string indicator updates with the label of the control you interacted with.
  3. Pressing the Stop button will stop the VI. 

Steps to Implement Code

  1. Add a while loop to the block diagrem.
  2. Right-click on the conditional terminal and select Create Control to add a Stop Button to the front panel.
  3. Add an event structure within the while loop.
  4. Add two or more controls to the front panel.
  5. Add an event case that is triggered by two or more different controls. (Instructions on how to do this here)
  6. Right-click the CtlRef terminal on the left Event Data Node and select Create»Property for Control Class»Label»Text
  7. Right-click on the output of the Property node to create a string constant to display on the front panel. 

Additional Information or References:

 

Method of Identifying what Control Triggered an Event Case FP.png

 

Method of Identifying what Control Triggered an Event Case BD.png


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

Tanya Visser
National Instruments
LabVIEW Group Manager

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

Comments
LabviewKK
Member
Member
on
it helps.