Displays a message in a dialog box, waits for the user to click a button, and returns an Integer indicating which button the user clicked.
MsgBox([prompt][, buttons] [, title]) |
The MsgBox function syntax has these named arguments:
Part | Description |
prompt |
Optional. String expression displayed as the message in the dialog box. The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used. If prompt consists of more than one line, you can separate the lines using a carriage return character (Chr(13)), a linefeed character (Chr(10)), or carriage return – linefeed character combination (Chr(13) & Chr(10)) between each line. |
buttons |
Optional. Numeric expression that is the sum of values specifying the number and type of buttons to display, the icon style to use, the identity of the default button, and the modality of the message box. If omitted, the default value for buttons is 0. |
title |
Optional. String expression displayed in the title bar of the dialog box. If you omit title, the application name is placed in the title bar. |
The buttons argument settings are:
Константа | Значение | Описание |
cdbOKOnly | 0 | Display OK button only. |
cdbOKCancel | 1 | Display OK and Cancel buttons. |
cdbAbortRetryIgnore | 2 | Display Abort, Retry, and Ignore buttons. |
cdbYesNoCancel | 3 | Display Yes, No, and Cancel buttons. |
cdbYesNo | 4 | Display Yes and No buttons. |
cdbRetryCancel | 5 | Display Retry and Cancel buttons. |
cdbCritical | 16 | Display Critical Message icon. |
cdbQuestion | 32 | Display Warning Query icon. |
cdbExclamation | 48 | Display Warning Message icon. |
cdbInformation | 64 | Display Information Message icon. |
cdbDefaultButton1 | 0 | First button is default. |
cdbDefaultButton2 | 256 | Second button is default. |
cdbDefaultButton3 | 512 | Third button is default. |
The first group of values (0–5) describes the number and type of buttons displayed in the dialog box; the second group (16, 32, 48, 64) describes the icon style; the third group (0, 256, 512) determines which button is the default. When adding numbers to create a final value for the buttons argument, use only one number from each group.
These constants are specified by ConceptDraw Basic for applications. As a result,
the names can be used anywhere in your code in place of the actual values.
Return Values
Constant | Value | Description |
cdbOK | 1 | OK |
cdbCancel | 2 | Cancel |
cdbAbort | 3 | Abort |
cdbRetry | 4 | Retry |
cdbIgnore | 5 | Ignore |
cdbYes | 6 | Yes |
cdbNo | 7 | No |
If the dialog box displays a Cancel button, pressing the ESC key has the same effect as clicking Cancel.
If some arguments are omitted, you must include the corresponding comma delimiters.
This example uses the MsgBox function to display a critical-error message in a dialog box with Yes and No buttons. The No button is specified as the default response. The value returned by the MsgBox function depends on the button chosen by the user.
Dim Msg, Style, Title, Response, MyString Msg = "Do you want to continue ?" ' Define message. Style = cdbYesNo + cdbCritical + cdbDefaultButton2 ' Define buttons. Title = "MsgBox Demonstration" ' Define title. Response = MsgBox(Msg, Style, Title) If Response = cdbYes Then ' User chose Yes. MyString = "Yes" ' Perform some action. Else ' User chose No. MyString = "No" ' Perform some action. End If |
See Also |
InputBox Function |