MsgBox Function

Usage

To show a OK dialog with a question mark you would type vbOKOnly+vbQuestion in the Buttons+Icon Parameter. The Dialog Title is a string which contains the title text. If this parameter is left blank, then the project name is used as the the Message Box's title

Msgbox "Are you sure?", vbYesNo+VBQuestion, "Front Page"

This shows a message box asking 'Are you sure' with yes and no buttons and a question icon. The Message Box function returns a number which tells you what button was pressed. The following constants are used:

Constant Button
vbOK OK Button
vbYes Yes Button
vbNo No Button
vbAbort Abort Button
vbRetry Retry Button
vbCancel Cancel Button
vbIgnore Ignore Button

Dim Ans As Integer
Ans = Msgbox("Are you sure?", vbYesNo+vbExclamation , "Front Page")
If Ans = vbYes Then
   Msgbox "You clicked yes"
Else
   Msgbox "You clicked no"
End If

This displays a message box asking 'Are you sure?', with yes and no buttons and a exclamation mark. If you click yes, then another message box is displayed saying 'You clicked yes', otherwise it displays a message saying 'You clicked no'.

If you want to include a variables contents in any of the parameters you can use an ampersand (&).

TheText = Text1.Text
Msgbox "The contents of Text1 is" & TheText

---OR---

Msgbox "The contents of Text1 is" & Text1.Text

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are 10 types of people in the world, those who can read binary, and those who can't.”