Prompting user to quit

Jiggerman75

Member
Joined
May 12, 2008
Messages
5
Programming Experience
Beginner
Hello

I'm not really good at programming and i apologise if this question has come up so many times in the forums, my question is when clicking the exit button i would like the program to ask if yopu want to quit, i know it has something to do with vb.YesNo but i cannot seem to work it out, please help it would be much appreciated.

thankyou
 
Would something like this suffice?

VB.NET:
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

        If MessageBox.Show("Are you sure you wish to exit?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

            e.Cancel = False

        Else

            e.Cancel = True

        End If

    End Sub
 
well i have just typed in this

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Dim intResponse As Integer

intResponse = MsgBox("Are you sure you would like to quit?", _
vbYesNo + vbQuestion, _
"quit")
If intresponse = vbYes Then
End
End If

End Sub

But it's working but will that piece of code just work the same without declaring anything
 
well i have just typed in this

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Dim intResponse As Integer

intResponse = MsgBox("Are you sure you would like to quit?", _
vbYesNo + vbQuestion, _
"quit")
If intresponse = vbYes Then
End
End If

End Sub

But it's working but will that piece of code just work the same without declaring anything
This code is much easier to read (and actually uses less memory):
VB.NET:
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

        If MessageBox.Show("Are you sure you wish to exit?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

            e.Cancel = False

        Else

            e.Cancel = True

        End If

    End Sub
 
Back
Top