February 18, 2019
Hot Topics:

Basics of VB Programming

  • November 20, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »

Message Boxes are used to display information to the user. You see them all the time in Windows and other programs.

Message boxes can be called like this:

MsgBox Prompt, Buttons/Icon, Title

The prompt is basically what you want it to say, the buttons/icon is what buttons you want and which icon you want and title is really self explanatory. e.g.

Msgbox "This is a test.",vbCritical,"Title"  

You can use the following constants for buttons:

  • vbOkOnly
  • vbOkCancel
  • vbYesNo
  • vbYesNoCancel
  • vbAbortRetryIgnore
  • vbRetryCancel

and these constants for icons:

  • vbQuestion
  • vbInformation
  • vbExclamation
  • vbCritical

An important thing that you need to be able to do is to translate what the user has done. e.g.

Dim iRes As Integer
iRes=MsgBox("Test Question?",vbYesNo+vbQuestion,"Title"
If iRes=vbYes Then
  Msgbox "The Yes button was clicked."
  Msgbox "The No button was clicked."
End If

To include the contents of a control, such as a text box, you can use the ampersand character (&) to concentate the prompt string (see No Strings Attached). e.g.

Msgbox "The contents is:" & Text1.Text

Page 2 of 6

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date