none
MsgBox Function

    Question

  • Ok, I know that this is an easy fix, but I'm not seeing it,

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            'warning before exiting program.

            MsgBox("Are you sure you want to exit program?", MsgBoxStyle.YesNo)

            If MsgBoxResult.Yes Then

                Application.Exit()

            ElseIf MsgBoxResult.No Then

                Return

            End If

        End Sub

    My problem is the program  exit when I click on both the yes and no buttons, I want it to return to the open form when I click "NO", What am I not seeing here. Thanks for the help. Cheers,  IrishWolf


    Failure is not an option! But sometime you need to look at those option.
    Thursday, May 13, 2010 6:20 PM

Answers

  • You aren't actually checking the result of the messagebox. You are showing a messagebox, but never looking at the result of what the user selects.

    Like this:

        If MsgBox("Are you sure you want to exit program?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
          Application.Exit()
        End If

    Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com
    • Marked as answer by IrishWolf Thursday, May 13, 2010 6:46 PM
    Thursday, May 13, 2010 6:36 PM
    Moderator

All replies

  • If I understand your question correctly just remove the ElseIf (and Return) statement.
     

    Paul ~~~~ Microsoft MVP (Visual Basic)
    Thursday, May 13, 2010 6:33 PM
  • You aren't actually checking the result of the messagebox. You are showing a messagebox, but never looking at the result of what the user selects.

    Like this:

        If MsgBox("Are you sure you want to exit program?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
          Application.Exit()
        End If

    Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com
    • Marked as answer by IrishWolf Thursday, May 13, 2010 6:46 PM
    Thursday, May 13, 2010 6:36 PM
    Moderator
  • Hey Kleinma,

    Thanks, I knew it was an easy fix, Thanks again. IrishWolf


    Failure is not an option! But sometime you need to look at those option.
    Thursday, May 13, 2010 6:46 PM
  • You're welcome. ;-)
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Thursday, May 13, 2010 6:50 PM