Summary: In this lesson, you will learn how to use the Case structure.
A Case
structure has two or more subdiagrams, or cases. Only one
subdiagram is visible at a time, and the structure executes only
one case at a time. An input value determines which subdiagram
executes. The Case structure is similar to case
statements or if...then...else statements in text-based
programming languages.
The case
selector identifier at the top of the Case
structure contains the case selector identifier in the center
and decrement and increment buttons on each side. Use the
decrement and increment buttons to scroll through the available
cases.
Wire an input
value, or selector, to the selector terminal to
determine which case executes. You must wire an integer, Boolean
value, string, or enumerated type value to the selector
terminal. You can position the selector terminal anywhere on the
left border of the Case structure. If you wire a
Boolean to the selector terminal, the structure has a
True case and a False case. If you
wire an integer, string, or enumerated type value to the
selector terminal, the structure can have up to
Case
structure. You must specify a default case to handle
out-of-range values or explicitly list every possible input
value. For example, if you specified cases for 1, 2, and 3 but
you get an input of 4, the Case structure executes
the default case.
default case for the Case
structure. You must specify a default case to
handle out-of-range values or explicitly list every possible
input value. For example, if you specified cases for
1, 2, and 3 but you get
an input of 4, the Case structure executes the
default case.
Case structure border to add,
duplicate, remove, or rearrange cases and to select a
default case.
Case structure instead of the Select
function. It is shown with the True case foremost
in the Case structure.
![]() Figure 1 |
Labeling tool to edit the
values, as shown in the block diagram in Figure 2.
![]() Figure 2 |
![]() Figure 3 |
Case structure. Inputs are available to all
subdiagrams, but subdiagrams do not need to use each
input. When you create an output tunnel in one case,
corresponding tunnels appear at the same position on the
border in all other cases.
Create>>Constant or Create>>Control
from the shortcut menu.
Use
Default If Unwired from the shortcut menu to use the
default value for the tunnel data type for all unwired
tunnels.
Case structure and are either
added or subtracted, depending on the value wired to the
selector terminal.
Case structure. The cases are shown overlapped
to simplify the illustration.
![]() Figure 4 |
True, the VI adds the numeric
values. Otherwise, the VI subtracts the numeric values.
![]() Figure 5 |
Integer is a text ring control located on the
Controls>>Text Controls palette that associates
numeric values with text items. If the text ring control
wired to the selector terminal is 0
(add), the VI adds the numeric values. If the
value is 1 (subtract), the VI
subtracts the numeric values. If the text ring control is
any other value than 0 (add) or
1 (subtract), the VI adds the
numeric values, because that is the default
case.
Case structure.
![]() Figure 6 |
String is add, the VI adds the
numeric values. If String is
subtract, the VI subtracts the numeric values.
Case structure.
![]() Figure 7 |
Case structure, the case
selector displays a case for each item in the enumerated
control. The Case structure executes the
appropriate case subdiagram based on the current item in the
enumerated control. In the block
diagram, if Enum is add,
the VI adds the numeric values. If Enum is
subtract, the VI subtracts the numeric values.
Case structure.
![]() Figure 8 |
Case structure, the case selector label
displays two cases, Error and No
Error, and the border of the Case
structure changes color--red for Error and
green for No Error. The Case
structure executes the appropriate case subdiagram based on
the error state.
selection
terminal, the Case structure recognizes only
the status Boolean of the cluster.
Comments, questions, feedback, criticisms?
"A full introductory course on programming with LabVIEW."