Msg Boxprompt[ buttons[ title

The MsgBoxQ function displays a dialog box with a message and waits for the user to close it by clicking a button. The message is the first argument (prompt). The simplest form of the MsgBox() function is as follows:

MsgBox("Your computer is running out of memory!")

This function displays a message in a dialog box that has an OK button. The MsgBoxQ function can display other buttons and/or an icon in the dialog box and return a numeric value, depending on which button was clicked. Table 3 summarizes the values for the buttons argument.

Table 3: The MsgBoxStyle Enumeration

Constant value

Button Values

OKOnly 0

OKCancel 1

AbortRetrylgnore 2

YesNoCancel 3

YesNo 4

RetryCancel 5 Icon Values

Critical 16

Question 32

Exclamation 48

Information 64 Default Button

DefaultButtonl 0

Defau1tButton2 256

Defau1tButton3 512

Defau1tButton4 768 Modality

ApplicationModal 0

SystemModal 4096


Displays OK button only. Displays OK and Cancel buttons. Displays Abort, Retry, and Ignore buttons. Displays Yes, No, and Cancel buttons. Displays Yes and No buttons. Displays Retry and Cancel buttons.

Displays Critical Message icon. Displays Warning Query icon. Displays Warning Message icon. Displays Information Message icon.

First button is default. Second button is default. Third button is default. Fourth button is default.

The user must respond to the message box before switching to any of the Forms of the current application.

All applications are suspended until the user responds to the message box.

Button values determine which buttons appear in the dialog box. Notice that you can't choose which individual buttons to display; you can only choose groups of buttons.

Icon values determine an optional icon you can display in the dialog box. These are the common icons used throughout the Windows user interface to notify the user about an unusual or exceptional event.

Default button values determine which button is the default one; pressing Enter activates this button. The constants ApplicationModal and SystemModal determine whether the message box is modal.

To combine any of these settings into a single value, simply add their values.

Finally, the MsgBox() function returns an integer, which indicates the button pressed, according to Table 4.

Table 4: The MsgBoxResult Enumeration

Constant value

OK 1

Cancel 2

Abort 3

Retry 4

Ignore 5

Yes 6

No 7

To display a dialog box with the OK and Cancel buttons and the Warning Message icon, add the values MsgBoxStyle.Exclamation and MsgBoxStyle.OKCancel as follows:

cont = MsgBox("This operation may take several minutes", _

MsgBoxStyle.Exclamation + MsgBoxStyle.OKCancel)

The value returned by the MsgBox() function is a member of the MsgBoxResult enumeration, which is shown in Table 4. Your program continues with the operation if the value of cont is MsgBoxResult.OK.

To display a dialog box with the Yes and No buttons and the Critical Message icon, add the values 4 and 16 as follows:

cont = MsgBox("Incomp1ete data. Would you like to retry?", _ MsgBoxStyle.YesNo + MsgBoxStyle.Critical)

If cont = MsgBoxResult.Yes Then ' user clicked Yes { prompt again )

Else ' user clicked No

{ exit procedure )

Endif chf6 bonus reference functions and statements

0 0

Post a comment