Diagram Disable structure: Difference between revisions
Add new page |
mNo edit summary |
||
| (5 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{ | {{TOCright}} | ||
{{LabVIEW Palette Object Information|palette=Functions Palette/Programming/Structures{{!}}Structures palette|type=structure|icon=Functions Palette - Programming - Structures - Diagram Disable Structure.png}} | |||
[[File:Diagram Disable Structure - Components.png|thumb|Components of a Diagram Disable structure]] | [[File:Diagram Disable Structure - Components.png|thumb|Components of a Diagram Disable structure]] | ||
A ''Diagram Disable Structure'' is a primitive [[Functions Palette/Programming/Structures|structure]] that can have one or more [[Subdiagram|subdiagrams]] (also known as "Cases"), one of which is executed at runtime. The programmer must manually specify the subdiagram to execute | A '''Diagram Disable Structure''' is a primitive [[Functions Palette/Programming/Structures|structure]] that can have one or more [[Subdiagram|subdiagrams]] (also known as "Cases"), one of which is executed at runtime. The programmer must manually specify the subdiagram to execute. Disabled subdiagrams do not break a VI if they contain broken wires or SubVIs. | ||
== Usage == | |||
== Code execution == | === Code execution === | ||
[[File:Diagram Disable Structure - Case selector with two disabled cases.png|thumb|Diagram Disable structure with two disabled cases]] | [[File:Diagram Disable Structure - Case selector with two disabled cases.png|thumb|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. | 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. | ||
| Line 17: | Line 18: | ||
|} | |} | ||
Only the ''Enabled'' case | Only the ''Enabled'' case will be executed, while all other cases will be ignored. The ''Enabled'' case is highlighted in the Case selector with the prefix <tt>[*]</tt>. | ||
=== Changing the Enabled case === | |||
== Changing the Enabled case == | |||
[[File:Diagram Disable Structure - Enable This Subdiagram.png|thumb|Enable the currently selected subdiagram]] | [[File:Diagram Disable Structure - Enable This Subdiagram.png|thumb|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. | 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. | ||
| Line 32: | Line 32: | ||
|} | |} | ||
=== Similarities with Case structures === | |||
== Similarities with Case structures == | |||
{{ambox|type=style|text=The examples below have indicators ''inside'' structures, which is considered bad practice. They need to be replaced once file versioning works again. --[[User:Logmanoriginal|Logmanoriginal]] ([[User talk:Logmanoriginal|talk]]) 20:40, 6 August 2019 (UTC)}} | {{ambox|type=style|text=The examples below have indicators ''inside'' structures, which is considered bad practice. They need to be replaced once file versioning works again. --[[User:Logmanoriginal|Logmanoriginal]] ([[User talk:Logmanoriginal|talk]]) 20:40, 6 August 2019 (UTC)}} | ||
The Diagram Disable structure is similar to the [[Functions Palette/Programming/Structures/Case Structure|Case structure]] | The Diagram Disable structure is similar to the [[Functions Palette/Programming/Structures/Case Structure|Case structure]]. Both can have multiple subdiagrams and only one will be executed at runtime. The key difference is, that Case structures are evaluated at runtime while Diagram Disable structures are evaluated at compile-time. Before the addition of Diagram Disable structures in [[LabVIEW 8|LabVIEW 8]], Case structures with a constant value wired to the Case Selector terminal were the only way to disable code.<ref>[https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P9NASA0 NI Knowledge Base: Comment Out or Disable Pieces of Code in LabVIEW]</ref> In that regard, Case structures work the same as Diagram Disable structures. | ||
[[File:Diagram Disable Structure - Example with Case structure.png|thumb|left|Unreachable code in a Case structure with constant value wired to the Case Selector terminal]] | [[File:Diagram Disable Structure - Example with Case structure.png|thumb|left|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 Diagram Disable structure, however, conveys the '''intention''' of the programmer and does not break the VI if a disabled case contains broken code. | ||
{| | {| | ||
| Line 49: | Line 47: | ||
|} | |} | ||
== Best practice == | == Best practice == | ||
* Use Diagram Disable structures instead of Case structures to disable sections of code. | * 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|debugging]] VIs. | * Use Diagram Disable structures to temporarily disable sections of code when [[Debugging|debugging]] VIs. | ||
| Line 70: | Line 66: | ||
|} | |} | ||
== See | == See Also == | ||
* [[DisableStructure class]] | |||
* [[Functions Palette/Programming/Structures/Conditional Disable Structure|Conditional Disable Structure]] | * [[Functions Palette/Programming/Structures/Conditional Disable Structure|Conditional Disable Structure]] | ||
* [[Functions Palette/Programming/Structures/Type Specialization Structure|Type Specialization Structure]] | * [[Functions Palette/Programming/Structures/Type Specialization Structure|Type Specialization Structure]] | ||
| Line 79: | Line 75: | ||
[[Category:Diagram Disable Structure]] | [[Category:Diagram Disable Structure]] | ||
[[Category:Structures]] | [[Category:Structures Palette]] | ||
[[Category:Debugging]] | [[Category:Debugging]] | ||
Latest revision as of 15:53, 25 June 2020
| Object information | |
|---|---|
| Owning palette(s) | Structures palette |
| Type | Structure |
| Requires | Basic Development Environment |
| Icon | |

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. Disabled subdiagrams do not break a VI if they contain broken wires or SubVIs.
Usage
Code execution

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 will be executed, while all other cases will be ignored. The Enabled case is highlighted in the Case selector with the prefix [*].
Changing the Enabled case

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 examples below have indicators inside structures, which is considered bad practice. They need to be replaced once file versioning works again. --Logmanoriginal (talk) 20:40, 6 August 2019 (UTC) |
The Diagram Disable structure is similar to the Case structure. Both can have multiple subdiagrams and only one will be executed at runtime. The key difference is, that Case structures are evaluated at runtime while Diagram Disable structures are evaluated at compile-time. Before the addition of Diagram Disable structures in LabVIEW 8, Case structures with a constant value wired to the Case Selector terminal were the only way to disable code.[1] In that regard, Case structures work the same as Diagram Disable structures.

A Diagram Disable structure, however, conveys the intention of the programmer and does not break the VI if a disabled case contains broken code.
![]() |
![]() |
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) |
|---|---|
| The Diagram Disable structure can automatically be replaced by a Type Specialization Structure | |
| The Diagram Disable structure was added. |

