Creating a Case Structure to Execute Conditional Code
- Updated2026-08-05
- 4 minute(s) read
Use a Case structure to specify two or more case subdiagrams that execute based on the input value you pass to the structure.
A Case structure includes the following components:
- Selector label: Displays the value or values for which the associated case executes. You can specify a single value or a range of values. Click the down arrow to select which subdiagram is visible from a menu. Click the side arrows to cycle through subdiagrams.
- Subdiagram (case): Contains the code that executes when the value that is wired to the case selector matches the value that appears in the selector label. You can modify the number or order of subdiagrams. The order determines only the order within the selector label menu, not how the code executes.
- Case selector: Selects which case to execute based on the value of the input data. The input data can be a Boolean, string, integer, enumerated type, or error cluster. The data type you wire to the case selector determines the allowed cases you can enter in the selector label.
To create a Case structure and specify values for case subdiagrams, complete the following steps.
-
Add a Case structure
to the block diagram.
Case structures are located on the palette.
-
Wire an input value of a supported data type to the case selector (
).
The data the Case structure receives at the case selector determines which subdiagram executes. A subdiagram executes when the data at the case selector matches a selector label.
You can position the case selector anywhere on the left border of the Case structure.
Wire different data types to the case selector. The selector label values and the number of subdiagrams you can use depend on the data type, as shown in the table.
Table 26. Valid Subdiagrams for Case Structure Data Types Supported Data Type Subdiagrams of Case Structure Boolean The structure has a True case and a False case. Error cluster By default, the structure has an Error case and a No Error case. You can also use an error cluster to handle specific errors by their numeric error code with a Case structure.
- Integer
- String
- Enumerated type
User-defined. The structure can have any number of cases. Tip You can convert a tunnel to the case selector. To do so, right-click the tunnel and select Replace with Case Selector. If the previous case selector is wired, LabVIEW converts the previously wired case selector to a tunnel. You can also use the Replace With Case Selector method to convert a tunnel to the case selector programmatically. -
Add objects inside
the Case structure to build subdiagrams that the
Case structure can execute.
If necessary, you can add or duplicate subdiagrams.
Tip You can specify a default subdiagram for case structures to avoid needing to create a unique subdiagram for every possible input. -
For each case, use the Labeling tool to enter a single value or lists and
ranges of values in the selector label at the top of the Case
structure.
In a given selector label, you can either enter a single value or span multiple values as follows.
Option Description Bounded range Specify a range of values with both an upper bound and a lower bound.
Syntax: .. between values.
Example: x..z
Open-ended range Specify a range of values with either an upper bound or a lower bound.
Syntax: .. before or after a value.
Example: ..x or x..
List Specify discontinuous values or multiple sets of values.
Syntax: , between values.
Example: x, z
You can combine lists and ranges in the same selector label.
Tip Using Enter on the keyboard can input a line break in some contexts. To reliably accept data instead, use Enter on the number pad or the Enter Text button (
).Note The behavior of values and ranges differs based on the data type that you wire to the case selector. For details about the values you can enter and their behavior, refer to Case Selector Label Behavior by Input Data Type.The value you enter in each selector label executes specific subdiagrams that correspond with the input value you pass to the structure.If you enter a selector label value that is not the same type as the object wired to the case selector, the value appears red. This indicates that the VI will not run. To fix the issue, delete the subdiagram or edit the value to a valid value.
Case Structure Example
For an example of using Case structures, refer to the Case Structure - Selector Data Types VI in the labview\examples\Structures directory.