Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
DIM Statement, MSGBOX Function, and MSGBOX Statement Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
' This example shows how the MSGBOX statement can be used to display messages
' or other information to the user. In addition to displaying information,
' the MSGBOX function returns a value indicating the button selected by the
' user. The DIM statement is used to share the value of a variable between
' procedures and the form module.
' When you run the example, select Command1 to see how the MSGBOX statement
' works and then select Command2 to see how the MSGBOX function works.
' Finally, click the form to display the value returned by the MSGBOX
' function.
' To try this example:
' 1. Choose New Project from the File menu
' 2. Choose New Form from the File menu to create a form with two command
' buttons
' 3. Press Alt+F4 to return to the programming environment
' 4. Copy the code example below to the form module
' 5. Press F5 to run the example
DIM SHARED Value#
SUB Command1_Click ()
MSGBOX "MSGBOX Statement, no value is returned", 1, _
"MSGBOX Statement Example"
END SUB
SUB Command2_Click ()
Value# = MSGBOX("MSGBOX Function value is returned", 1, _
"MSGBOX Function Example")
END SUB
SUB Form_Click ()
PRINT "Value returned from MSGBOX function was" + STR$(Value#)
SELECT CASE Value#
CASE 1
PRINT "OK button was selected"
CASE 2
PRINT "Cancel button or ESC key was selected"
END SELECT
END SUB