Chapter 13. Getting User Input with Message Boxes and Input Boxes

This chapter shows you how to start adding a user interface to recorded or written code in order to increase the code's power and functionality.

You'll learn the three easiest ways of communicating with the user of your code, the two easiest ways of enabling the user to make decisions in a procedure, and the easiest way of soliciting input from the user. Along the way, you'll see how to decide what is the best way to communicate with the user in any given set of circumstances. This will set the scene for starting an examination of more complex interactions with the user via custom dialog boxes, later in the book.

In most applications, VBA offers up to five ways of communicating with the user of a procedure:

  • Displaying messages on the status bar at the bottom of the window (if the application provides a status bar). This is a bit limited, but it can be an effective way of communicating with the user.

  • Displaying a message box (usually in the middle of the screen). Message boxes are useful both for communicating with users and for providing them with the means to make a single choice based on the information you give them. You'll spend the bulk of this chapter working with message boxes.

  • Displaying an input box (again, usually in the middle of the screen). You can use input boxes to communicate with users, but their primary purpose is to solicit one item of information. Input boxes also provide users with the means of making a single choice to direct the flow of a procedure, although the mechanism for presenting this choice is much more limited than that in a message box. You'll look at input boxes toward the end of this chapter.

  • Displaying a dialog box (once again, usually in the middle of a screen). You can use dialog boxes both to communicate with the user and to let them make a number of choices. Dialog boxes are best reserved for those times when other forms of communication won't suffice; in other words, there's no point in using a dialog box when a simple message box or input box will do. You'll look at creating custom dialog boxes by using VBA user forms later in the book.

  • Communicating directly through the document or the application's interface. For example, the user can fill out a form, click a button on the screen, and wait for a reaction.

In this chapter you will learn to:

  • Display messages on the status bar

  • Display message boxes

  • Display input boxes

  • Understand the limitations of message boxes and input boxes

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.69.168