Question Validate a Message Box

keigo

Active member
Joined
Oct 27, 2008
Messages
29
Programming Experience
Beginner
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MessageBox.Show("Would you like to proceed to next step?", "Status", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    End Sub

Here I am trying to validate if user checks 'Yes' or 'No'. I tried using If Else but did not go far.

I use this:

If MessageBoxButtons.YesNo = 1 Then
Me.Close()
End If

The program should terminate if user clicks 'Yes', and back to Run if user clicks 'No'.

It was a bad try, perhaps anyone could share what kind of property value I should put instead of =1?

Or maybe there are more codes I need to write. I would listen for alternative ways if any suggestions. Thanks a bunch.

*Thanks very much.
 
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim dlgResult As DialogResult
    dlgResult = MessageBox.Show("Would you like to proceed to next step?", "Status", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    If dlgResult = DialogResult.Yes Then
        Me.Close()
    End If
End Sub
 
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim dlgResult As DialogResult
    dlgResult = MessageBox.Show("Would you like to proceed to next step?", "Status", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    If dlgResult = DialogResult.Yes Then
        Me.Close()
    End If
End Sub
Even easier:
VB.NET:
Select Case Messagebox.Show("Would you like to proceed to next step?", "Status", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    Case DialogResult.Yes
        'Code for the yes button
    Case DialogResult.No
        'Code for the no button
End Select
Simply add another case for any other buttons you have.
 
Thanks a lot to Sehnsucht and JuggaloBrotha,

I did not expect so many possible answers. Thanks a lot, really.
 
Back
Top