Thursday, August 14, 2014

SubVI Panels as Modal Dialogs - A How-To Guide

It's fairly common in LabVIEW applications to display the front panel of a subVI in order to retrieve inputs from the user, or to just display information. Unfortunately, there are several "gotchas" associated with this seemingly simple use-case. Follow these steps to ensure your modal subVI panel functions properly.
  1. Handle the opening and closing of the subVI panel programmatically. You may be tempted to use the SubVI Node Setup right-click option on the subVI to easily display the subVI panel when it executes:

    The biggest problem with using this option is that your subVI is not allowed to run any initialization code before displaying its panel. If your subVI needs to move/disable/hide controls and indicators, you have no control over when it is "safe" to display the subVI panel when using this option. So instead, use the FP.Open method to display the subVI panel once you have initialized it, and use the FP.Close method to close it once the user dismisses the subVI dialog:

  2. Configure the VI Properties of the subVI properly. You'll want the Window Appearance in VI Properties to be set to "Custom", with custom settings like this:

    Note that the menu bar, title bar, and scrollbars have all been hidden. Also note that the Show Abort Button option is disabled...this is so a user can't abort your entire application by pressing Ctrl-. while your subVI dialog is active. The Window Behavior is set as Modal, and note that the Show front panel when called option is disabled, to avoid the same issues described in point #1 above.
  3. Call your modal dialog subVI dynamically. Whenever you run a VI, all of its statically-called subVIs (i.e. normal subVIs sitting on its diagram) are reserved for running. This means that none of the subVIs are in edit mode, since they may be executed by the top-level VI at some point. An unfortunate side effect of this behavior is that any reserved subVI that also has a modal window appearance will be immediately displayed if its front panel is already open. And since it is a modal window, you cannot dismiss it (since it's not running, it's just reserved for running). The best way to avoid this problem (other than always making sure your modal subVI panels are closed before running) is to call the modal dialog subVI dynamically:

    By changing the subVI to Load and retain on first call, it will no longer be reserved for running when you run the top-level VI, and as a result, will not ever hang your app if you accidentally leave it open before running.
Follow these steps for dialog subVIs (show/hide the panel programmatically, configure properties correctly, and call dynamically) to make sure your LabVIEW applications with user-visible subVI panels are robust and easy to develop and debug.


  1. Great tips, thanks. Especially #3 - I've been burnt by that many a time, but had never thought of that solution. Going back to change a few things now...

  2. Agreed on #3 - nifty trick I've also been burned by. Nice post

  3. Glad to see you back here, Darren.
    In my 25 years of LabVIEW programming, I have never once used the NODE SETUP dialog.
    I too have been burned by accidentally leaving a modal window open when I start the main running. Usually followed by much foul language, and CAD work (ctrl-alt-delete).

  4. A few months ago someone told me to use Front Panel Window:Behavior Property to make a SubVI modal. So put this property node twice in your VI. At Start up to make it modal and right before closing the VI to change back to default behavior. So this "unfortunate side effect [..] that [..] a modal window appearance will be immediately displayed if its front panel is already open." will not occur.

  5. This post cleared up exactly what I was wondering about while developing popup windows. It seems FP.Open and Close do not even need to be wired to a reference.