Home > Resources > Engineering > LabVIEW Dialog Snippet
Engineering

LabVIEW Dialog Snippet

LabVIEW block-diagram snippet from ITM's iTestSystem showing a user dialog for channel setup

A custom dialog is one of the most repeated pieces of code in a LabVIEW application: a settings window, a confirmation, a prompt for a serial number before a test starts. LabVIEW’s built-in One Button and Two Button Dialog functions cover simple messages. Once a dialog needs its own controls, defaults or validation, you need a VI of your own. This snippet is the framework ITM’s developers start from, and it gets a new dialog running in under a minute:

  1. Create a new VI.
  2. Drag the snippet at the top of this post (Figure 1) onto the block diagram. LabVIEW turns the image into code. The snippet was saved in LabVIEW 2020, so it opens in 2020 or later.
  3. Open File » VI Properties » Window Appearance and select Dialog (Figure 2).
  4. Optional: clear Same as VI name and enter a custom window title.
  5. Save and run the VI.
LabVIEW VI Properties Window Appearance dialog setting
Figure 2 – VI Properties/Windows Appearance

How the framework works

The block diagram is a while loop around an event structure, so the dialog sits idle until the operator does something.

  • Settings in, settings out. The settings cluster rides in a shift register. Whatever the operator changes is carried round the loop and returned when the dialog closes. Replace the cluster with the data your dialog edits.
  • One event case per button. The snippet shows the OK: Value Change case: it sets Stop to True to end the loop and Cancelled? to False. Give Cancel its own case that returns True, so the calling VI knows to discard the settings.
  • Errors pass straight through. error in and error out run along the bottom of the loop, so a dialog called after an upstream failure passes that error on instead of hiding it.

What the Dialog setting changes

Choosing Dialog is a shortcut for a group of window settings. The front panel opens when the VI is called as a subVI and closes when it finishes. The window is modal, so it stays in front of the application until the operator responds. The menu bar and toolbar are hidden. Click Customize… to see or change each one. Two more settings worth making:

  • Map Enter to OK and Esc to Cancel on each button’s Properties » Key Navigation tab.
  • Set VI Properties » Window Run-Time Position to Centered, so the dialog opens in the middle of the screen.

The error case structure

Inside the OK case is another snippet we use everywhere (Figure 3). Wire error in to a case structure’s selector and it gets No Error and Error cases. Put your code in No Error; the Error case passes the incoming error straight through, so nothing runs on bad data.

LabVIEW error case structure snippet
Figure 3 – Error case structure snippet

What’s next?

More from the LabVIEW Channel: sorting cluster arrays, subpanels and splitter bars.

Building your own LabVIEW dialogs and snippets? Talk to the engineers behind ITM’s LabVIEW development work.

Related solutions

Software

iTestSystem and the LabVIEW-based software platform behind ITM’s data acquisition tools. Explore →

Data Acquisition

DAQ hardware built to work hand-in-hand with the LabVIEW software driving it. Explore →

Consulting

Engineering consulting for custom LabVIEW development and test software architecture. Explore →

Recent insights