MsgBox Function

Default Buttons

Most of the time when you show a message box, you know what the most likely answer will be. For example, if you ask "Do you want to save changes to Document 1?", most of the time, the answer will be Yes. If you aren't sure, choose the option which means that the user doesn't lose any work. For example, if he/she closed an application and accidentally pressed return when a message box displayed asking him/her to save changes, and its default answer was No, he would lose all his work.

To specify a default button simply add a vbDefaultButton1, or vbDefaultButton2 etc in the flags parameter. For example

Msgbox "Do you want to save changes?", vbYesNo+vbExclamation+vbDefaultButton1 , "Front Page"

would set the default button as Yes

Msgbox "Do you want to save changes?", vbYesNoCancel+vbExclamation+vbDefaultButton3 , "Front Page"

would set the default button as No.

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.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov