Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 94,002 times

Contents

Related Categories

MsgBox Function - Default Buttons

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.

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • alternative to Msgbox function

    Posted by forvihang on 17 May 2005

    hi,
    is it possible to have something which will display the information (information is one or two lines of text) for few seconds and disappear. if i use msgbox for it, there are many message boxes i...

  • This code doesn't work.

    Posted by JLG2000 on 18 Mar 2005

    I get the following error:

    [code]It is invalid to show a modal dialog or form when the application is not running in UserInteractive mode. Specify the ServiceNotification or DefaultDesktopOnly styl...

  • Add icon in menu bar

    Posted by khurem on 12 Apr 2004

    Hello
    dear i dont know how i can add icons in menu bar in visual basic .
    plaease help me to solve this problem.
    khuram

  • Posted by HyperHacker on 21 Apr 2003

    No, you need to make a new form that looks like a message box for that. :p

  • This is how you write it :D

    Posted by tauro_fuerte on 08 Oct 2002

    [blue]Dim[/blue] ans [blue]As String[/blue]
    ans = MsgBox("Would you like to save changes?", vbYesNoCancel)
    [blue]If[/blue] ans = vbYes [blue]Then[/blue]
    [green]'Put your Yes commands in here[/gree...