MSGBOX statement


Display a message box containing a text string and optional title, using one or more styles.


MSGBOX txt$ [, [style%], title$]

? txt$ [, [style%], title$]


The MSGBOX statement comprises the following elements:


Text to display within the message box.


Optional parameter which determines the appearance of the message box. Some styles may be combined (OR'ed together) to specify the button and icon displayed in the message box. If style& is omitted, PowerBASIC substitutes %MB_OK. The following are some of the more common styles used with the MSGBOX statement (also see the MSGBOX function for more information):


Display OK button (default)


Display Error icon (stop sign)


Display Information icon ("i")


Display Warning icon (exclamation)


Application Modal - Despite the name, the user can continue to interact with other dialogs without dismissing the MSGBOX. (default)


System Modal - Operates identically to %MB_APPLMODAL, except the MSGBOX is given the %WS_EX_TOPMOST style so that it remains above all other windows and dialogs.


Task Modal - All top-level windows belonging to the current application are disabled until the MSGBOX is dismissed. %MB_TASKMODAL is commonly used to display a truly modal MSGBOX.

Additional styles may be found in WIN32API.INC, in the section prefixed with %MB_. If you are interested in which button the user selects, use a MSGBOX function rather than a MSGBOX statement.


Determines the title to be displayed in the caption of the message box. If title$ is not specified, "PowerBASIC" is used automatically.

The MSGBOX statement may be represented by the query (?) character as a shortcut. This is similar to the behavior in the PowerBASIC Console Compiler (PB/CC), where the query character is recognized as a synonym for the PRINT statement. This can simplify the creation of certain test code, since the query character provides similar functionality in both compilers.


Strings displayed by the MSGBOX function are displayed only up to the first $NUL character, if any.

See also

INPUTBOX$, MSGBOX function, TXT pseudo-object


MSGBOX "Got here, hit OK to continue",, "Title of subroutine 123"

MSGBOX "Current value of X% is: " & STR$(x%)

MSGBOX "Paused, click OK to continue!"

MSGBOX "Click OK to reboot the universe…", %MB_TASKMODAL OR %MB_ICONERROR, "Reality has crashed!"