MsgBoxFunction MsgBox Statement

  1. MsgBox ( msg, [type] [, title])

Displays a message in a dialog box and waits for the user to choose a button.

The first parameter msg is the string displayed in the dialog box as the message. The second and third parameters are optional and respectively designate the type of buttons and the title displayed in the dialog box.

MsgBox Function returns a value indicating which button the user has chosen; the MsgBox statement does not.

Value

Meaning

Group 1

0

Display OK button only

1

Display OK and Cancel buttons

2

Display Abort, Retry, and Ignore buttons

3

Display Yes, No, and Cancel buttons

4

Display Yes and No buttons

5

Display Retry and Cancel buttons

Group 2

16

Stop Icon

32

Question Icon

48

Exclamation Icon

64

Information Icon

Group 3

0

First button is default

256

Second button is default

512

Third button is default

Group 4

768

Fourth button is default

0

Application modal

4096

System modal

The first group of values (1-5) describes the number and type of buttons displayed in the dialog box; the second group (16, 32, 48, 64) describes the icon style; the third group (0, 256, 512) determines which button is the default; and the fourth group (0, 4096) determines the modality of the message box. When adding numbers to create a final value for the argument type, use only one number from each group. If omitted, the default value for type is 0.

title:

String expression displayed in the title bar of the dialog box. If you omit the argument title, MsgBox has no default title.

The value returned by the MsgBox function indicates which button has been selected, as shown below:

Value

Meaning

1

OK button selected.

2

Cancel button selected.

3

Abort button selected.

4

Retry button selected.

5

Ignore button selected.

6

Yes button selected.

7

No button selected.

If the dialog box displays a Cancel button, pressing the Esc key has the same effect as choosing Cancel.

More:

Example: