|Owning palette(s)||Structures palette|
|Requires||Basic Development Environment|
A Case Structure is a primitive Structure that can have multiple Subdiagrams (also known as "Cases"), one of which is selectively executed at runtime. A selector value determines which case is executed at runtime. The Structure autmatically adapts to the data type connected to the Case selector and must have exactly one Subdiagram for each possible value of the connected data type, or a Default case to handle undefined values.
Supported data types
The Case Structure automatically adapts to following data types:
Some features are only available for specific data types.
Boolean Case Structure
The Boolean Case Structure is the default Structure when placed from the Functions Palette. It has exactly two cases: True and False.
Integer Case Structure
The Integer Case Structure uses an Integer as selector value and can have as many cases as the specific Integer type supports. Non-integer values (Fixed-point, Single Precision, Double Precision, Extended Precision) are rounded according to IEEE 754-1985. Complex numbers (Complex Single, Complex Double, Complex Extended) are not supported and will break the VI.
Integer cases can have ranges.
|Range (open)||3..||Executes if the value is greater than or equal to 3|
|Range (closed)||3..10||Executes if the value is greater than or equal to 3 and lower than or equal to 10|
|List||3, 5, 7||Executes if the value is either 3, 5 or 7|
Ranges are automatically sorted in ascending order by LabVIEW.
The default representation for Integer values is Decimal. This representation can be changed to Decimal, Hex, Octal or Binary from the right-click menu option Radix.
Enum Case Structure
The Enum Case Structure uses the string interpretation of the value to label cases. Internally, however, LabVIEW uses the Integer representation to select cases. Renaming Enum values has no effect on the Case Structure.
Enum Case Structures support range selectors similar to the Integer Case Structure:
|Range (open)||"First"..||Executes if the value is greater than or equal to "First".|
|Range (closed)||"First".."Third"||Executes if the value is greater than or equal to "First" and lower than or equal to "Third".|
|List||"First", "Third"||Executes if the value is "First" or "Third".|
Values are automatically sorted by their Integer representation and not by name.
Add Case for Every Value
Because Enums have a finite amount of values, LabVIEW provides a simple way to add cases for every value via the right-click menu option Add Case for Every Value. This automatically adds cases for all missing values.
String Case Structure
The string Case Structure uses a case-sensitive string as selector value.
Case Insensitive Match
By default the Case Structure does a case sensitive match. This behavior can be changed by using the Case Insensitive Match option from the right-click menu.
From LabVIEW 2015 onward, the Case Structure shows "A=a" at the bottom left corner if Case Insensitive Match is enabled.
|Type||Selector||Description (standard)||Description (Case Insensitive Match)|
|Exact match||"a"||Executes if the value is exactly "a"||Executes if the value is either "a" or "A"|
|Range (open)||"a"..||Executes if the value is greater than or equal to "a"||Executes if the value is greater than or equal to "A" (lower on the ASCII table)|
|Range (closed)||"a".."z"||Executes if the value is greater than or equal to "a" and lower than "z" (not including "z")||Executes if the value is greater than or equal to "A" and lower than "z" (not including "z")|
|List||"a", "o", "z"||Executes if the value is either "a", "o" or "z"||Executes if the value is either "A", "a", "O", "o", "Z" or "z"|
Ranges are automatically sorted in ascending order by LabVIEW.
Error Case Structure
Multiple error cases
Since LabVIEW 2019 it is possible to have multiple error cases for specific error codes. Previously this was only possible by unbundling the code element from the Error Cluster and connect it to an Integer Case Structure inside the error case. Error codes are handled like Integer values and therefore can specify range selectors:
|All Errors||Error ..||Executes for any error|
|Range (open)||Error 3..||Executes if the error code is greater than or equal to 3|
|Range (closed)||Error 3..10||Executes if the error code is greater than or equal to 3 and lower than or equal to 10|
|List||Error 3, 5, 7||Executes if the error code is either 3, 5 or 7|
A Default case is required when using error ranges.
The Subdiagram Label adds a label at top of each Subdiagram. It is hidden by default and can be shown via the right-click menu option Visible Items >> Subdiagram Label.
While the position of the label is fixed, its height can be adjusted for each Subdiagram.
- <Shift-Enter> creates a new case after the current case.
- <Ctrl-Shift-Enter> duplicates the current case.
- Use Lookup Tables instead of Case Structures to return values from a constant non-consecutive list of items (i.e. error code => error message).
- If two cases perform the same operation, remove one case and use the range selector instead.
- Use Subdiagram labels instead of free labels to document Subdiagrams.
- Use Linked Input Tunnels for data wires that must be wired through all cases (changed or unchanged).
- Use the Match Pattern function or Match Regular Expression function instead of range selectors for string Case Structures.
- Set output terminals to Use Default Value if only some cases need to return values.
- Do not connect data wires if they are not used inside the Case Structure. Those wires should be wired around the Structure.
- Do not add a Default case for Enum values if the Structure is supposed to handle all values at all times.
- Do not use Case Structures to disable code (i.e. by wiring a False constant), use the Diagram Disable Structure instead.
Tips and tricks
- Wire an error cluster to a Case Structure to turn it into an Error Case Structure.
|Added support for multiple error cases in Error Case Structures.||This feature was requested on the LabVIEW Idea Exchange by Hueter on 19.01.2010 and later confirmed by Darren to be included in LabVIEW 2019 on 30.05.2019. |
|Added an indicator for the Case Structure if Case Insensitive Match is enabled.||This feature was requested on the LabVIEW Idea Exchange by Matthias_H on 08.08.2014 and later confirmed by Darren to be included in LabVIEW 2015 on 17.08.2015. |