Programmatically Determine if a VI Is Running in a LabVIEW SubPanel

Updated Aug 3, 2023

Environment

Software

  • LabVIEW

Using LabVIEW, you may need to programmatically modify some aspects of a VI if it is running in a SubPanel. This article will help you to determine if a VI is inside of a SubPanel control at run-time.

Even if there is no VI property that allows you to directly determine this, there is a method. Certain front panel properties are read-only when the VI is running in a SubPanel - Attempting to write to these properties returns 1148 error. Hence, this approach can then be used to determine whether the VI is running in a SubPanel.


Aspects to keep in mind when using subpanel controls:

  • The subVI must not be in memory when the main VI is run.
  • The subVI front panel is only displayed in the subpanel container when the main VI is running. When the main VI is stopped, the subVI's front panel is removed from the SubPanel control.

 

Here are the following steps to trigger this specific 1148 error :
 

1. Start by creating a simple VI, with the same block diagram as the one illustrated in the Loading a Front Panel in a Subpanel Control LabVIEW documentation and save it to the location of your choice while keeping it open.

Note : As an alternative, you can also start by opening the existing LabVIEW project example called Containers.lvproj, which can be found under the Controls and Indicators\Containers Directory Structure, using the NI Example Finder . In this LabVIEW project, open the Multiple VIs in a Subpanel.vi.

2. Create a second VI which will be used as a sub-VI. It will be called by the main VI created in previous step and loaded within the SubPanel control. For the purpose of this procedure, there is no need to add any Front Panel/Diagram elements. Once created, save this sub-VI in the same location as the main VI and close it.
 

Note : If you started by using the existing Containers LabVIEW project example, no additional VI creation is needed as some are already created in the project.
 

3. On the block diagram of the main VI, add a Property Node  right after the Insert VI Invoke Method and select the Front Panel Window >> Resizable property. With a right click on the node, select Change To Write and wire a boolean constant to set the value.

Resizable Property Node Final

4. Compare the code portion of the error cluster to 1148 value so you can check if the condition is met. This comparison can be used to change the status of a boolean indicator for instance.

Error code comparison

5. Run the VI.
 

    Attempting to write in a read-only front panel property for a VI which is loaded in a SubPanel control should result in getting 1148 error code.

    The following snippet is a simple VI, illustrating the easiest way to generate the 1148 error code
     

    SubPanel Main VI Snippet
    Note : This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
     

    In this example, a boolean indicator is used to indicate whether the VI is running in a SubPanel.