Summary: In this exercise, the objective is to use the Case structure in a VI. Complete the following steps to build a VI that checks whether a number is positive. If the number is positive, the VI calculates the square root of the number. Otherwise, the VI returns an error message.
![]() |
![]() |
Place the Case
structure, located on the Functions>>Execution
Control palette, on the block diagram. Click
the decrement or increment
button to select the False case.
Greater or Equal
to 0? function, located on the
Functions>>Arithmetic &
Comparison>>Express Comparison palette, on
the block diagram. This function returns
True if Number is greater
than or equal to 0.
Right-click the numeric
constant and select Properties
from the shortcut menu. Select the Format and
Precision tab. Set Digits of
precision to 1, select
Floating point notation, and click the
OK button to ensure there is no data
conversion between the constant and the numeric
indicator outside the Case structure.
One Button
Dialog function, located on the
Functions>> All Functions>>Time &
Dialog palette, on the block diagram. This
function displays a dialog box that contains the
message Error...Negative Number.
Right-click the message terminal of the
One Button Dialog function, select
Create>>Constant from the shortcut
menu, type Error...Negative Number in
the constant, and click the Enter
button on the toolbar or click outside the
control. Refer to the lesson on Strings and File I/O for more
information about strings.
True case of the
Case structure.
Square Root
function, located on the Functions>>Arithmetic
& Comparison>>Express Numeric palette, on the
block diagram. This function returns the square root of
Number. Wire the function as shown in Figure 3.
![]() |
Square Root.vi in the
C:\Exercises\LabVIEW Basics I directory.
Number is positive, the VI executes the
True case and returns the square root of
Number. If Number is negative,
the VI executes the False case, returns
-99999, and displays a dialog box with the
message Error...Negative Number.
"A full introductory course on programming with LabVIEW."