The Input Box function

The InputBox function enables a user to input data through a dialog box (see Figure 3.5). Notice that the generic dialog box has two buttons: OK (the default selection) and Cancel. These buttons can be customised (see Chapter 10). The dialog box also contains a title (in this case "Ask Age"), a prompt ("How old are you?") and a text box for the user's input. The InputBox function takes at least one parameter: a prompt to the user. The format for using this function in a VBA program is illustrated in the following example:

strAge = InputBox("How old are you?", "Ask Age")

Here, the prompt to the user is the message "How old are you?" The title of the dialog box is "Ask Age" and this is given from the second parameter in the InputBox function. When this command is run in VBA, the cursor will flash in the edit line while waiting for the user to respond with some data. In Figure 3.5, the value 48 has been entered; this value will now be stored in a place called strAge. This is known as a variable because any value could have been entered in the text box; i.e., it could vary. Variables are studied in detail in Chapter 5.

Figure 3.5 The InputBox function

0 0

Post a comment