MsgBox ( ) Function



TABLE OF CONTENTS


Basic Form:


     intVariable1 = MsgBox ( strMsg [, intButtonsIcon][, strTitle][, strHelpFile, context])


Where,

  • strMsg is a string (either a string enclosed in quotes or a string variable) to be used as text in the box.
  • intButtonsIcon is an expression or value that describes the buttons and icon you want in the box as well as which button has the focus (see tables below).
  • strTitle is a string to be used in the title bar of the dialogue box.
  • strHelpFile is a string that identifies the Help file to use to provide context-sensitive help for the dialog box.
  • context is the Help context number assigned to the appropriate help topic.
  • The MsgBox() function must always be assigned to an integer variable (e.g., intVariable1 above).
  • Buttons, the icon to be displayed, and which button has the focus can be determined by the following tables. If values are used from two or three of the tables the values should be added together.

Notes:

  • strMsg can be a maximum of 1024 characters long.
  • strMsg is a required argument for MsgBox( )
  • If strMsg consists of more than one line, you can use Chr(10) & Chr(13) to force a carriage return/linefeed at the end of a line.
     

  Back to Top

  • Buttons included in the dialog box can be:


intButtonsIcon Expression

Value

What It Tells MsgBox to Display

vbOKOnly

0

OK Button

vbOKCancel

1

OK and Cancel Buttons

vbAbortRetryIgnore

2

Abort, Retry, and Ignore Buttons

vbYesNoCancel

3

Yes, No, and Cancel Buttons

vbYesNo

4

Yes and No Buttons

vbRetryCancel

5

Retry and Cancel Buttons

vbMsgBoxHelpButton

16384

Help Button

      Note: the values of intButtonsIcon Expression are "Named Literals" and not variables. They're defined to correspond exactly to the intButtonsIcon Values. In other words, values in the first column are equivalent to those in the second.

Back to Top

 

  • The icon to be displayed in the dialog can be: 

intButtonsIcon

Value

What It Tells MsgBox to Display

vbCritical

16

Critical Message Icon

vbQuestion

32

Warning Query Icon

vbExclamation

48

Warning Message Icon

vbInformation

64

Information Message Icon

vbApplicationModal

0

System Application Modal dialog box

vbSystemModal

4096

System Modal dialog box

      Note: the values of intButtonsIcon Expression are "Named Literals" and not variables. They're defined to correspond exactly to the intButtonsIcon Values. In other words, values in the first column are equivalent to those in the second.

  Back to Top

 

  • Additional codes which can be used to control MsgBox's appearance are as follows:

 

intButtonsIcon Expression

Value

What It Tells MsgBox to Display

vbMsgBoxSetForeground

65536

The MsgBox as the foreground window

vbMsgBoxRight

524288

MsgBox text as right-aligned text

vbMsgBoxRtlReading

1048576

Text as right to left reading on Hebrew and Arabic systems

      Note: the values of intButtonsIcon Expression are "Named Literals" and not variables. They're defined to correspond exactly to the intButtonsIcon Values. In other words, values in the first column are equivalent to those in the second.

 Back to Top

 

  • The default button (the one with the focus) in the dialog box can be:

intButtonsIcon Expression

Value

What It Tells MsgBox

vbDefaultButton1

0

The first button has the focus

vbDefaultButton2

256

The second button has the focus

vbDefaultButton3

512

The third button has the focus

vbDefaultButton4

768

The fourth button has the focus

 

      Note: the values of intButtonsIcon Expression are "Named Literals" and not variables. They're defined to correspond exactly to the intButtonsIcon Values. In other words, values in the first column are equivalent to those in the second.

 Back to Top

 

  • The MsgBox function can send back information to the program; it can return one of the seven "return values" below:

 

Named Constant

Return Value

Tells Us the User Clicked the:

vbOK

1

OK Button

vbCancel

2

Cancel Button

vbAbort

3

Abort Button

vbRetry

4

Retry Button

vbIgnore

5

Ignore Button

vbYes

6

Yes Button

vbNo

7

No Button

 

    A program can test for either the integer Named Constant or the Return Value.


Example:


    IntQuery = MsgBox ("Do you want to see a graph of the results?", vbYesNoCancel + _ vbDefaultButton2, "Graph Query")

(Note that the underscore is a line continuation character and not part of the MsgBox function syntax)

Results in a dialog box with the title "Graph Query" in the title bar, a question mark icon in a bubble on the left side of the dialog box, and Yes, No, and Cancel buttons underneath. The No button has the focus.

Back to Top

arrowl2Return to the Visual Basic Page 

Comments

 

Latest Version! NetObjects Fusion 10 

 

Copyright 1998 Rich Hamper 

All Rights Reserved

 

Last Updated:

Sunday, January 20, 2008