MsgBox Function


MsgBox Function

Class

Microsoft.VisualBasic.Interaction

Syntax

     Dim result As MsgBoxResult = MsgBox(prompt[, buttons[, title]]) 


prompt (required; String)

The text of the message to display in the message dialog box.


buttons (optional; MsgBoxStyle enumeration)

One or more constants (either added or Or'd together) that set various display and action properties of the dialog box. The constants are taken from the Microsoft.VisualBasic.MsgBoxStyle enumeration:

Enumeration member

Value

Description

OKOnly

0

Buttons: Display OK button only

OKCancel

1

Buttons: Display OK and Cancel buttons

AbortRetryIgnore

2

Buttons: Display Abort, Retry, and Ignore buttons

YesNoCancel

3

Buttons: Display Yes, No, and Cancel buttons

YesNo

4

Buttons: Display Yes and No buttons

RetryCancel

5

Buttons: Display Retry and Cancel buttons

Critical

16

Icon: Display Critical Message icon

Question

32

Icon: Display Warning Query icon

Exclamation

48

Icon: Display Warning Message icon

Information

64

Icon: Display Information Message icon

DefaultButton1

0

Default Button: Default to first button

DefaultButton2

256

Default Button: Default to second button

DefaultButton3

512

Default Button: Default to third button

DefaultButton4

768

Default Button: Default to fourth button

ApplicationModal

0

Modality: Response required to continue application

SystemModal

4096

Modality: Response required to continue application, and the message box appears on top of all other windows


If omitted, this parameter defaults to OKOnly.


title (optional; String)

The title displayed in the title bar of the message dialog box. If omitted, the name of the application or project is used.

Description

The MsgBox function displays a dialog box containing a message, buttons, and an optional icon. A value indicating the button clicked by the user is returned by the function, one of the Microsoft.VisualBasic.MsgBoxResult enumeration values:

Enumeration member

Value

Button clicked

OK

1

OK

Cancel

2

Cancel

Abort

3

Abort

Retry

4

Retry

Ignore

5

Ignore

Yes

6

Yes

No

7

No


If the message box contains a Cancel button, the Esc key simulates a click on that button. The Enter key simulates a click on the currently highlighted button.

Usage at a Glance

  • prompt can contain approximately 1,024 characters, including special characters such as the vbCrLf constant.

  • Application modality means that the user cannot access other parts of the application until a response to the message box has been given.

  • System modality used to mean that all applications were suspended until the message box was closed. However, this functionality was only supported in Microsoft Windows 3.x and earlier. In newer versions of Windows, using system modality causes the message box to "stay on top" of all application windows.

  • The message box is always displayed in the center of the screen.

  • If your application is to run out-of-process on a remote machine, you should remove all MsgBox functions, since they will not appear on the user's workstation but on the monitor of the remote system.

  • MsgBox should never be used in ASP.NET applications.

  • The System.Windows.Forms.MessageBox class provides enhanced message box functionality, including the ability to specify online help information.

Version Differences

In VB 6, the MsgBox function includes a helpFile parameter and a context parameter, both used with online help files. These two parameters are not supported in .NET.

See Also

InputBox Function




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net