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 dialogThe 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 paletteExpress Dialogs: Display Message and Prompt UserThe 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 dialogWhen 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 dialogWhen 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 DialogsThere 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 RootsThis 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.
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.")
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.
Square Root VI Logic
The Select FunctionIn 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
|