Jump to content

Diagram Disable structure

From LabVIEW Wiki
Revision as of 20:40, 6 August 2019 by Logmanoriginal (talk | contribs) (Add new page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Components of a Diagram Disable structure

A Diagram Disable Structure is a primitive structure that can have one or more subdiagrams (also known as "Cases"), one of which is executed at runtime. The programmer must manually specify the subdiagram to execute during runtime. Disabled subdiagrams do not break a VI if they contain broken wires or SubVIs.


Code execution

Diagram Disable structure with two disabled cases

The Diagram Disable structure can have one or more cases, each of which can be Enabled or Disabled. However, only one subdiagram can be Enabled at any time.

Enabled The subdiagram will be executed at runtime.
Disabled The subdiagram will be ignored.

Only the Enabled case is executed, while all other cases are ignored during execution. The Enabled case is highlighted in the Case selector with the prefix [*].


Changing the Enabled case

Enable the currently selected subdiagram

The Enabled case can be changed via the right-click menu option Enable This Subdiagram for disabled cases or Disable This Subdiagram for the enabled case.

Enable This Subdiagram Enables the currently selected subdiagram (must be disabled) and disables all other subdiagrams.
Disable This Subdiagram Disables the currently selected subdiagram (must be enabled).


Similarities with Case structures

The Diagram Disable structure is similar to the Case structure, which can also have multiple subdiagrams, one of which is executed at runtime. In fact, before the invention of Diagram Disable structures in LabVIEW 8, Case structures were the only way to disable code by wiring a constant value to the Case Selector terminal.[1] In that regard, Case structures work the same as Diagram Disable structures.

Unreachable code in a Case structure with constant value wired to the Case Selector terminal


A Diagram Disable structure, however, conveys the intention of the programmer and does not break a VI if the code inside a disabled case breaks.

Broken disabled code in a Diagram Disable structure does not break the VI
Broken disabled code in a Case structure with constant value wired to the Case Selector terminal breaks the VI


Best practice

  • Use Diagram Disable structures instead of Case structures to disable sections of code.
  • Use Diagram Disable structures to temporarily disable sections of code when debugging VIs.
  • Use a version control system instead of Diagram Disable structures to manage code revisions.
  • Use Conditional Disable structures instead of Diagram Disable structures to enable/disable subdiagrams based on compile-time conditions.

History

Version Change(s)
LabVIEW 2019 The Diagram Disable structure can automatically be replaced by a Type Specialization Structure
LabVIEW 8 The Diagram Disable structure was added.

See also

References