Dialogs


We'll switch gears for a moment; we will digress from structures to tell you about dialog boxes so that you can use them in the next activity.

Can LabVIEW carry on a conversation with you? For now, you can make LabVIEW pop-up dialog windows that have a message and often some response buttons, like "OK" and "Cancel," just like in other applications.

The dialog functions are accessible from the Programming>>Dialog & User Interface palette. LabVIEW provides you with three types of pop-up dialog boxes: one-, two-, and three-button. In each case, you can write the message that will appear in the window, and specify labels on the buttons. The two-button dialog function returns a Boolean and the three-button dialog function returns an enumerated value indicating which button was pressed. In any case, LabVIEW pauses execution of the VI until the user responds to the dialog box. The dialog box is said to be modal, which means that even though windows (such as other VIs' front panels) will continue to run and be updated, the user can't select any of them or do anything else via the mouse or keyboard until he or she has dealt with the dialog box.

As an example, suppose you wanted to add a dialog box to confirm a user's choice on critical selections. In the example shown in Figures 6.28 and 6.29, a dialog box is presented when the user presses the computer's self-destruct button.

Figure 6.28. Dialog.vi front panel, displaying a two-button dialog that allows the user to confirm their action


Figure 6.29. Dialog.vi block diagram, containing the Two Button Dialog function used to display the dialog


The dialog functions, both standard and express, bring up a dialog box containing a message of your choice. You can find these functions in the Programming>>Dialog & User Interface subpalette of the Functions palette, shown in Figure 6.30.

Figure 6.30. Express and standard dialogs on the Dialog & User Interface palette


Express Dialogs: Display Message and Prompt User

The quickest way to create a dialog that displays a message or prompts the user for information is to use the Display Message and Prompt User Express VIs (respectively).

Figure 6.31 shows how easy it is to configure the Display Message express VI to ask the user a simple Yes or No question. (Open the configuration dialog by double-clicking the Express VI, or by selecting Properties from its pop-up menu.)

Figure 6.31. Display Message Express VI and its configuration dialog


When Display Message is called, it will display a two-button dialog (because we have configured it to Display second button, in our example), like the one shown in Figure 6.32. (You can leave the Display second button checkbox unchecked to display only one button.)

Figure 6.32. Display Message Express VI dialog


For situations where you want to prompt the user to enter data, such as their name and password, you can use the Prompt User Express VI, shown in Figure 6.33.

Figure 6.33. Prompt User Express VI and its configuration dialog


When we call this VI, it will display a dialog (see Figure 6.34) containing the controls specified in the Inputs section of the configuration dialog, along with the specified text message and buttons.

Figure 6.34. Prompt User Express VI dialog


Standard Dialogs: One, Two, and Three Button Dialogs

There are three standard dialog functions: One Button Dialog, Two Button Dialog, and Three Button Dialog, shown in Figures 6.35 through 6.37.

Figure 6.35. One Button Dialog


Figure 6.36. Two Button Dialog


Figure 6.37. Three Button Dialog


The One Button Dialog stays open until you click the OK button, while the Two Button Dialog box remains until you click either the OK or the Cancel button. The Three Button Dialog remains open until you click one of the buttons or close the window, and it tells you which of these four events occurred. (The Two Button Dialog defaults to Cancel if you close the window.) You can also rename these buttons by inputting "button name" strings to the functions. These dialog boxes are modal; in other words, you can't activate any other LabVIEW window while they are open. They are very useful for delivering messages to or soliciting input from your program's operator.

Activity 6-3: Square Roots

This activity will give you some practice with Case Structures and dialog boxes. You will build a VI that returns the square root of a positive input number. If the input number is negative, the VI pops up a dialog box and returns an error.

1.

Open a new panel.

2.

Build the front panel shown in Figure 6.38.

Figure 6.38. The front panel of the VI you will build during this activity


The Number digital control supplies the input number. The Square Root Value indicator will display the square root of the number.

3.

Open the block diagram window. You will construct the code shown in Figures 6.39 and 6.40.

Figure 6.39. False case




Figure 6.40. True case


4.

Place the Case Structure (Programming>>Structures subpalette) in the block diagram window. As you did with the For Loop and While Loop, click with the structure cursor and drag to define the boundaries you want.

The Greater or Equal? function returns a Boolean value, so the Case Structure remains in its default Boolean form.

Remember, you can display only one case at a time. To change cases, click on the arrows in the top border of the Case Structure. Note that the previous picture shows two cases from the same structure so you will know what to build. Do not create two different Case Structures for this activity!

5.

Select the other diagram objects and wire them as shown in the preceding illustration. Make sure to use the Help window to practice displaying terminal inputs and outputs!

Greater or Equal? Function

Greater or Equal? function (Programming>>Comparison subpalette). In this activity, checks whether the number input is negative. The function returns a TRUE if the number input is greater than or equal to zero.

Square Root Function

Square Root function (Programming>>Numeric subpalette). Returns the square root of the input number.

Numeric Constant

Numeric Constants (Programming>>Numeric subpalette). "99999.0" supplies the error case output, and "0" provides the basis for determining if the input number is negative.

One Button Dialog Function

One Button Dialog function (Programming>>Dialog & User Interface menu). In this exercise, displays a dialog box that contains the message "Error . . . Negative Number."

String Constant

String Constant (Programming>>String subpalette). Enter text inside the box with the Operating or Labeling tool. (You will study strings in detail in Chapter 9, "Exploring Strings and File I/O.")

In this exercise, the VI will execute either the TRUE case or the FALSE case of the Case Structure. If the input Number is greater than or equal to zero, the VI will execute the TRUE case, which returns the square root of the number. If Number is less than zero, the FALSE case outputs a 99999.00 and displays a dialog box containing the message "Error . . . Negative Number."

Remember that you must define the output tunnel for each case, which is why we bothered with the 99999.00 error case output. When you create an output tunnel in one case, tunnels appear at the same location in the other cases. Unwired tunnels look like hollow squares. Be sure to wire to the output tunnel for each unwired case, clicking on the tunnel itself each time, or you might accidentally create another tunnel.


6.

Return to the front panel and run the VI. Try a number greater than zero and one less than zero.

7.

Save and close the VI. Name it Square Root.vi and place it in your MYWORK directory.

Square Root VI Logic

If (Number >= 0) then    Square Root Value = SQRT (Number) Else    Square Root Value = -99999.0    Display Message "Error ... Negative Number" End If 



The Select Function

In simple "if-then-else" cases, you might find it more convenient to use LabVIEW's Select function, which works much like a Case Structure (see Figure 6.41).

Figure 6.41. Select function


The Select function, found in the Programming>>Comparison subpalette of the Functions palette, returns a value of t if the s input value is TRUE, and returns a value of f if the s input is FALSE. This function could accomplish almost the same thing as the Case Structure in the last activity, with the exception of popping up the dialog box (see Figure 6.42).

Figure 6.42. The Select function used to conditionally switch between two possible outputs





LabVIEW for Everyone. Graphical Programming Made Easy and Fun
LabVIEW for Everyone: Graphical Programming Made Easy and Fun (3rd Edition)
ISBN: 0131856723
EAN: 2147483647
Year: 2006
Pages: 294

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net