MsgBox Function

Displays a dialog box containing a message and returns a value.

Syntax:


MsgBox (Text As String [,Type As Integer [,Dialogtitle As String]])

Return value:

Integer

Parameter:

Text: String expression displayed as a message in the dialog box. Line breaks can be inserted with Chr$(13).

DialogTitle: String expression displayed in the title bar of the dialog. If omitted, the name of the respective application is displayed.

Type: Any integer expression that specifies the dialog type and defines the number and type of buttons or icons displayed. Type represents a combination of bit patterns (dialog elements defined by adding the respective values):

Values

Named constant

Integer value

Definition

MB_OK

0

Display OK button only.

MB_OKCANCEL

1

Display OK and Cancel buttons.

MB_ABORTRETRYCANCEL

2

Display Abort, Retry, and Ignore buttons.

MB_YESNOCANCEL

3

Display Yes, No, and Cancel buttons.

MB_YESNO

4

Display Yes and No buttons.

MB_RETRYCANCEL

5

Display Retry and Cancel buttons.

MB_ICONSTOP

16

Add the Stop icon to the dialog.

MB_ICONQUESTION

32

Add the Question icon to the dialog.

MB_ICONEXCLAMATION

48

Add the Exclamation Point icon to the dialog.

MB_ICONINFORMATION

64

Add the Information icon to the dialog.

128

First button in the dialog as default button.

MB_DEFBUTTON2

256

Second button in the dialog as default button.

MB_DEFBUTTON3

512

Third button in the dialog as default button.


Return value:

Named constant

Integer value

Definition

IDOK

1

OK

IDCANCEL

2

Cancel

IDABORT

3

Abort

IDRETRY

4

Retry

IDIGNORE

5

Ignore

IDYES

6

Yes

IDNO

7

No


Error codes:

5 Invalid procedure call

Example:


Sub ExampleMsgBox
Dim sVar As Integer
 sVar = MsgBox("Las Vegas")
 sVar = MsgBox("Las Vegas",1)
 sVar = MsgBox( "Las Vegas",256 + 16 + 2,"Dialog title")
 sVar = MsgBox("Las Vegas", MB_DEFBUTTON2 + MB_ICONSTOP + MB_ABORTRETRYCANCEL, "Dialog title")
End Sub

Please support us!