View contents of this chapter

Format of the MsgBox() Function

intResponse = MsgBox(prompt[, buttons] [, title])

intResponse holds the function's integer return data type. The first argument (prompt) is a string that displays as the message box's message. The third argument determines the style of the buttons. The next argument determines the title that appears in the message box's title bar.

Play Sound If a message is too long to fit in one line of the message box, VB automatically breaks the line into two or more lines.

Suppose you need to wait for the user before printing a report. You can show the following message box.

intResponse = MsgBox ("Click when you are ready")

The following figure shows this simple message box:

Figure 9.1

If you don't specify the buttons argument, VB displays one command button with the word OK by default. Moreover, If you omit title, the application name is placed in the title bar. The following table lists integer button style values you can use for the MsgBox() function.

Value Constant Description
0 vbOKOnly Display OK button only.
1 vbOKCancel Display OK and Cancel buttons.
2 vbAbortRetryIgnore Display Abort, Retry, and Ignore buttons.
3 vbYesNoCancel Display Yes, No, and Cancel buttons.
4 vbYesNo Display Yes and No buttons.
5 vbRetryCancel Display Retry and Cancel buttons.

Consider the following code segment:

intResponse = MsgBox ("Are you ready?", vbYesNo)

The following figure shows this simple message box:

Figure 9.2

The following If statement can be used to handle the previous message box:

If (intResponse = vbYes) Then
  'Code for handling the Yes button)
Else
  'Code for handling the No button)
End If

 



© Universal Teacher Publications        INDEX Previous Screen Next Screen