The Case Structure
Graphical Case Selection: Choosing One Execution Path
Graphical case selection lets a LabVIEW program choose which code executes from an input value. You use it when an instrument has operating modes, a calculation depends on a condition, or an output needs different treatment under different circumstances. LabVIEW implements this choice with its Case Structure. Each time the structure executes, exactly one of its cases executes.
Follow the selector
The selector is the input value that determines which case executes. Wire it to the selector terminal on the structure border. The label at the top identifies the value or values associated with the displayed case. Changing the displayed case while editing lets you inspect another subdiagram; it does not choose the runtime case.
For a Boolean selector s, the governing relationship is
Here, x represents input data and each f represents the calculation placed inside that case. The selected calculation produces y. The other case does not execute during that execution of the structure.
A comparison can produce the Boolean selector. For example, comparing a measured temperature with 320 K using greater than or equal gives True at the threshold and above. The True case could output 5.00 V and the False case 0.00 V. At 315 K, the comparison is False, so only the False case executes.
Match values to case labels
The selector's data type determines the available labels. Common choices include Booleans, integers, strings, and enumerations. An enumeration provides a defined set of named choices, such as operating modes.
Selector type | Example case labels | How selection works |
|---|---|---|
Boolean | True and False | Selects one of two cases |
Integer | 0, 1..3, Default | Matches a value or an inclusive range |
String | "Measure", "Standby", Default | Matches a text value |
Enumeration | Measure and Standby | Matches a named item of the enumeration |
For integer labels, 1..3 includes 1, 2, and 3. Cases must cover the possible selector values. A Default case handles values not explicitly matched by another label; it is particularly useful for integer or string selectors with many possible inputs.
A Default case does not execute after a matching case. It is another possible selection. Cases also do not run in the order in which you browse them in the editor.
Give every output a defined value
A tunnel is a connection through a structure boundary that carries data into or out of its cases. Input tunnels make data available inside the structure, although an individual case may not need every input.
For an ordinary output tunnel with Use Default If Unwired disabled, every case must supply a value. The values supplied by different cases must have compatible data types. An unwired case can therefore break the VI even when the case currently displayed is fully wired.
Enabling Use Default If Unwired changes this behavior: an unwired case supplies the tunnel data type's default value. For an ordinary numeric tunnel, that value is zero. This setting does not preserve the previous output, and it does not select the Default case.
When checking your diagram, inspect every case and every output tunnel. Explicitly wire intended fallback values, and check values exactly at comparison thresholds or integer-range endpoints. These checks reveal gaps that a successful run through just one case can miss.
What to remember
- The selector determines which single case executes.
- Case labels cover selector values; Default handles unmatched values.
- Put conditional calculations inside the appropriate case.
- Define every output deliberately; an unwired tunnel does not remember its previous value.
Example: Graphical Case Selection for a Sensor Offset
A sensor-conditioning program receives a voltage x. A comparison node evaluates x≥1.20 V and wires the Boolean result to a case selector. Inside the True case, the program calculates
where 3.00 is a dimensionless gain. The required False-case output is 0.00 V. Both cases use the same numeric output tunnel, with Use Default If Unwired disabled.
a) For x=1.65 V, identify the selected case and calculate y.
Compare the input with the threshold before using a case's formula. Since 1.65 V≥1.20 V, the selector is True and the True case executes. Subtract the offset first, then apply the gain:
Wire this calculated voltage to the output tunnel inside the True case. The output is 1.35 V.
b) For x=1.20 V, identify the selected case and calculate y. Does a zero output identify which case executed?
The comparison includes equality, so an input exactly at the threshold selects True. Substitute the threshold voltage into the True-case calculation:
A zero output does not uniquely identify the executed case: the True calculation gives zero at the threshold, and the False case is also specified to output zero. Identify the case from the selector value.
c) For x=0.95 V, identify the selected case and output. Explain the required False-case wiring.
Here 0.95 V<1.20 V, so the comparison is False. The True-case subtraction and multiplication do not execute. The required selected output is
Place a numeric zero constant inside the False case and wire it to the same output tunnel. Since Use Default If Unwired is disabled, leaving this connection unwired would break the VI. A fully wired True case does not supply an output for False.
A technician is reviewing a LabVIEW Case Structure before connecting a mode control and a measurement wire. Match each component to its role in the structure.
Executes when the selector value matches none of the values listed for the other cases
Makes data from outside the border available inside any case that uses it
Displays the matching value or values associated with the case currently shown in the editor
Receives the runtime value that determines which case executes
Carries a result from the executing case to code outside the border
Case selector
Default case
Output tunnel
Selector label
Input tunnel
A LabVIEW program uses an integer mode selector and a voltage input x. Its cases all wire the same numeric output tunnel as follows:
Case label | Output |
|---|---|
0..4 | x+0.20 V |
5..9 | 2x |
Default | −1.00 V |
For mode 9 and x=0.65 V, what voltage leaves the output tunnel?