VB YES NO CANCEL - VB.NET Visual studio 2003 Message box

Posted on 2006-05-11
Last Modified: 2008-01-09
I bulding a windows application using visual studio 2003.

I want to show a messagebox with yes no and cancel button on it."Message",    ------------ )

also let me know, how to grab the output of the selection made from the messagebox.

please help me in this simple question.

Question by:Apu_Shah
    LVL 17

    Accepted Solution

    Dim dlgResult As DialogResult

    dlgResult = MessageBox.Show("Message", "Caption here", MessageBoxButtons.YesNoCancel)

    Select Case dlgResult
         Case DialogResult.Yes
               'Yes code here
         Case DialogResult.No
               'No code here
         Case DialogResult.Cancel
               'Cancel code here
    End Select
    LVL 3

    Expert Comment

    Dim intResult As Integer
            intResult = MessageBox.Show("Message", "My Caption", MessageBoxButtons.YesNoCancel)

            Select Case intResult
                Case DialogResult.Yes
                Case DialogResult.No
                Case DialogResult.Cancel

            End Select
    LVL 27

    Expert Comment

    This should do it

           Dim Message As String = "Message"
            Dim Caption As String = "Error Caption"
            Dim Buttons As MessageBoxButtons = MessageBoxButtons.YesNoCancel

            Dim Result As DialogResult

            'Displays the MessageBox

            Result = MessageBox.Show(Message, Caption, Buttons)

            ' get the user selection

            If Result = Windows.Forms.DialogResult.Yes Then
             'Or Result=Windows.Forms.DialogResult.No
             'Or Result=Windows.Forms.DialogResult.Cancel

                ' Do something
            End If
    LVL 2

    Author Comment

    Thanks all,

    All answers are correct.

    ZeonFlash response time was good enough to get him points.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    This video discusses moving either the default database or any database to a new volume.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now