Msgbox function language reference

Time:2022-5-19

describe
Displays a message in the dialog box, waits for the user to click the button, and returns a value indicating the button the user clicked.
Grammar
  MsgBox(prompt[, buttons][, title][, helpfile, context])
The syntax of msgbox function has the following parameters:

Parameter description
Prompt is a string expression displayed as a message in the dialog box. The maximum length of prompt is about 1024 characters, depending on the width of the characters used. If the prompt contains multiple lines, the lines can be separated by carriage return (Chr (13)), line feed (Chr (10)) or a combination of carriage return and line feed (Chr (13) & Chr (10)).
Buttons numerical expression is the sum of the number and type of the specified display buttons, the icon style used, the identification of the default button and the message box style. For values, see the settings section. If omitted, the default value of buttons is 0.
Title The string expression displayed in the title bar of the dialog box. If you omit the title, the name of the application is displayed in the title bar.
Helpfile string expression that identifies the help file that provides context sensitive help for the dialog box. If helpfile is provided, context must be provided. Not available on 16 bit system platforms.
The context numeric expression is used to identify the context number assigned to a help topic by the author of the help file. If context is provided, helpfile must be provided. Not available on 16 bit system platforms.

set up
The buttons parameter can have the following values:
Constant value description
The OK button only displays konly.
Vbokcancel 1 displays the OK and Cancel buttons.
Vbabortretryignore 2 displays the discard, Retry, and ignore buttons.
Vbyesnocancel 3 displays the yes, no, and Cancel buttons.
Vbyesno 4 displays yes and no buttons.
Vbretrycancel 5 displays retry and Cancel buttons.
Vbcritical 16 displays the critical information icon.
Vbquestion 32 displays the warning query icon.
Vbexclamation 48 displays a warning message icon.
Vbinformation 64 displays the information message icon.
Vbdefaultbutton1 0 the first button is the default button.
Vbdefaultbutton2 256 the second button is the default button.
Vbdefaultbutton3 512 the third button is the default button.
Vbdefaultbutton4 768 the fourth button is the default button.
Vbapplicationmodal 0 application mode: the user must respond to the message box to continue working in the current application.
Vbsystemmodal 4096 system mode: all applications are suspended before the user responds to the message box.

The first set of values (0 – 5) is used to describe the type and number of buttons displayed in the dialog box; The second set of values (16, 32, 48, 64) is used to describe the style of the icon; The third set of values (0, 256, 512) is used to determine the default button; The fourth set of values (0, 4096) determines the style of the message box. When adding these numbers to produce the buttons parameter value, only one number can be taken from each group of values.

Return value
The msgbox function has the following return values:
Constant value button
Vbok 1 OK
Vbcancel 2 cancel
Vbabort 3 give up
Vbretry 4 retry
Vbignore 5 ignore
Vbyes 6 yes
Vbno 7 No

explain
If both helpfile and context are provided, the user can press F1 to view the help topic corresponding to the context.
If the dialog box displays a cancel button, pressing ESC has the same effect as clicking cancel. If the dialog box contains help buttons, there is context sensitive help provided for the dialog box. However, no value is returned until you click another button.

The following example uses the msgbox function to display an information box, and the return value indicates which button is pressed:

Dim MyVar
  MyVar = MsgBox (“Hello World!”, 65, “msgbox example”) ‘myvar contains either 1 or 2,’ depending on the button pressed.