Message Boxes

Written by Rod Wing.

Message Boxes are a means to quickly display information to the user.  Message boxes can also used to get basic Yes/No or Boolean type user input. Using Message boxes to get this kind of input can eliminate the need to develop custom UserForms to gather that information.

The MsgBox function returns a VbMsgBoxResult value which is an enumerated list with each item  corresponding the the button on the message box dialog selected by the user. The following code snippets illustrate the working with the MsgBox function to collect user input.

Dim msgResult As VbMsgBoxResult
' Display Yes and No buttons
    msgResult = MsgBox("Do you want to continue?", _
                                      vbYesNo, "My Macro")
    If msgResult = VbMsgBoxResult.vbYes Then
            'User clicked Yes button
            'User clicked No button
    End If
CAD Training
' Display OK and Cancel buttons
    msgResult = MsgBox("Do you want to continue?", _
                                   vbOKCancel, "My Macro")
    If msgResult = VbMsgBoxResult.vbOK Then
            'User clicked OK button
            'User clicked Cancel button
    End If
CAD Training
' Display Abort, Retry, and Ignore buttons
    msgResult = MsgBox("Do you want to continue?", _
                           vbAbortRetryIgnore, "My Macro")
    Select Case msgResult
        Case VbMsgBoxResult.vbAbort
            'User clicked Abort button
        Case VbMsgBoxResult.vbIgnore
            'User clicked Ignore button
        Case VbMsgBoxResult.vbRetry
            'User clicked Retry button
    End Select


CAD Training



Rod Wing

Rod is the Senior Systems Analyst at EnvisionCAD and has extensive experience in GIS, cartography, plotting, scanning, raster editing/manipulation, publishing, and file/data translations. He instructs MicroStation classes ranging from fundamentals to advanced.


Leave a Reply

Your email address will not be published. Required fields are marked *