Results 1 to 6 of 6
  1. #1
    Old Merits
    Join Date
    Jan 2009
    Posts
    1,060
    BG Level
    6

    Quick VB Express 2008 Question

    Looking to have a button to exit the program with a message box popping up asking for confirmation to exit. Here's what I have so far that's not working as intended/don't know what to write for "no".

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    MsgBox("Are you sure you want to exit the program? All inputted information will be lost.", vbYesNo, "Exit")
    If MsgBoxResult.Yes Then
    Me.Close()
    ElseIf MsgBoxResult.No Then
    'Watisthisidonteven
    End If
    End Sub

    Clicking "Yes" does close it, but also clicking "No" closes it as well, even if theres no code which I'm not sure why. The "Yes" button should close the program, and the "No" button should close the messagebox and show the program again.

  2. #2
    Banned.

    Join Date
    Jul 2005
    Posts
    5,821
    BG Level
    8
    FFXI Server
    Sylph
    WoW Realm
    Arthas

    Assign the message box to a var.

    Code:
            Dim DisBeVar As DialogResult = MsgBox("Are you sure you want to exit the program? All inputted information will be lost.", vbYesNo, "Exit")
            If DisBeVar = Windows.Forms.DialogResult.Yes Then
                Application.Exit()
            End If
    You don't need to have an elseif if the only value you're looking for is yes.

  3. #3
    Old Merits
    Join Date
    Jan 2009
    Posts
    1,060
    BG Level
    6

    Perfect, thanks loli<3

  4. #4
    Banned.

    Join Date
    Jul 2005
    Posts
    5,821
    BG Level
    8
    FFXI Server
    Sylph
    WoW Realm
    Arthas

    To do it without defining anything you can also do:
    Code:
             If MsgBox("Are you sure you want to exit the program? All inputted information will be lost.", vbYesNo, "Exit") = Windows.Forms.DialogResult.Yes Then
                Application.Exit()
            End If
    which is what I think you were originally trying to do.

  5. #5
    Smells like Onions
    Join Date
    Nov 2009
    Posts
    1
    BG Level
    0
    FFXI Server
    Titan
    WoW Realm
    Aerie Peak

    I accept with information
    Quote Originally Posted by Senoska View Post
    Assign the message box to a var.

    Code:
            Dim DisBeVar As DialogResult = MsgBox("Are you sure you want to exit the program? All inputted information will be lost.", vbYesNo, "Exit")
            If DisBeVar = Windows.Forms.DialogResult.Yes Then
                Application.Exit()
            End If
    You don't need to have an elseif if the only value you're looking for is yes.

  6. #6
    Old Merits
    Join Date
    Jan 2009
    Posts
    1,060
    BG Level
    6

    Oh, I bet you do.

Similar Threads

  1. Quick car antifreeze/coolant question
    By Andarvi in forum General Discussion
    Replies: 33
    Last Post: 2010-04-30, 10:19
  2. quick windows media player question
    By Lavik in forum General Discussion
    Replies: 0
    Last Post: 2008-12-27, 14:53
  3. hey quick question
    By eike in forum General Discussion
    Replies: 4
    Last Post: 2005-11-19, 18:16
  4. quick question once you've gone thru server mait.
    By in forum General Discussion
    Replies: 6
    Last Post: 2004-11-12, 09:32