A MsgBox() and InputBox() OverviewYou use input boxes and message boxes when you need to ask the user questions or display error messages and advice to the user. As stated earlier, the form's controls don't often work well for such user dialog boxes. For example, suppose the user is to enter a sales code of A, B, or C to indicate a discount to be used in a total calculation. Users don't always know what's expected of them, so a message box can pop up when the user enters a bad value and the message box can explain that the user needs to enter only A, B, or C. If the user enters an invalid code, your program could display an error message.
The Text Box controls that you've seen are great for getting values from the user. Other controls that you'll learn as you progress through this book also accept the user's input from the keyboard or mouse. Nevertheless, Visual Basic's controls just aren't enough to handle all the input that your program will need. Input boxes are great to use when the user must respond to certain kinds of questions. Text boxes and other controls are fine for getting fixed input from the user, such as data values with which the program will compute. Input boxes are great for asking the user questions that arise only under certain conditions. Input boxes always give the user a place to respond with an answer. Note that there is more than one way for the user to respond to an input box. The user can answer the question by typing the name of the server and pressing Enter or clicking OK. The user also can click Cancel whether or not the user entered the server name. Therefore, the program must be capable of reading the user's entered answer as well as responding to a Cancel command button press. Responding to message box and input box command buttons is part of the processing that you'll learn about in the remaining sections of this lesson. |
|
![]() |
![]() |
|||