MsgBox

User dialog function.

The MsgBox function displays a standard Windows dialog box.

Usage

Used to provide information feedback to the user. If you prefer to display information without any user interaction, use MsgFrame function.

Syntax

MsgBox(<Message> [, [<Type>] [,<Title>] [,<timeout>]]])
or
ret=MsgBox(<Message> [, [<Type>] [,<Title] [,<timeout>]]])

Parameters

<Message>, string or integer to be displayed in the dialog box. In order to display numeric and string variables together, you must first convert numbers to a string (using the Str$ function - see the examples below).

<Type>, optional integer, sum of the values below used for specifying buttons and icons in the dialog box. The default value is 0 (only an OK button). <Type> cannot be a variable. If <Type> is omitted, you must include the field separator (,), see the example.

Type of buttons:

0

OK button only

1

OK and Cancel

2

Cancel, Retry and Ignore

3

Yes, No and Cancel

4

Yes and No

5

Retry and Cancel

Type of icons:

16

Critical message

32

Confirmation

48

Warning

64

Information

Default button:

0

First button

256

Second button

512

Third button

 

<Title>, optional string, title of the dialog box.

<timeout>, optional integer. If after <timeout> in seconds, no button has been clicked, the message box vanishes, and a return code of 128 is returned (if the message box has only an OK button, the return code when the message box vanishes after <timeout> is 1).

Return value

Return value for the corresponding selected button:

1

OK

2

Cancel

3

Quit

4

Retry

5

Ignore

6

Yes

7

No

If the dialog box displays a Cancel button, pressing Escape is the same as clicking Cancel.

Examples

 

Ret = MsgBox("Hello", 65, "Title") ' Box with 2 buttons (OK and Cancel, plus the Information icon)

MsgBox("Hello") ' Box with no title and one OK button

MsgBox(msg$, x, title$)

Msgbox(number)

Msgbox("You found " + str$(number) + " occurrences") 'As number is an integer, it must be first converted to a string using str$ function, and then str$(number) can be concatenated to other strings using the + operator.

MsgBox("Hello", , "Title")

MsgBox("Hello", , "Title",10)