So I have this two forms.. I have a command button on the second form that when I clicked, a message box pops out and ask you if you want to go in the first form. The 'Yes' worked but the 'No' doesn't work, the first form still shows.. can you help me guys.. thanks..

here's my code:

Public Class Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("FUCK I'M WASTED", MsgBoxStyle.YesNo)
If vbYes Then
Form1.Show()

Else
''''''''''''
End If

End Sub
End Class

Recommended Answers

All 3 Replies

That is because vbYes is always true. Instead of that, use

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If MsgBox("**** I'M WASTED", MsgBoxStyle.YesNo) = vbYes Then
Form1.Show()
End If

End Sub
End Class

Also, in .Net world, you should use MessageBox.

Add the following code to your button and see if it works:

Dim Result As DialogResult
Result = MessageBox.Show("**** I'M WASTED", "**** I'M WASTED", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
If Result = System.Windows.Forms.DialogResult.Yes Then
    Me.Hide()
    Form2.Show()
ElseIf Result = System.Windows.Forms.DialogResult.No Then
    'Your Code Here
End If
Member Avatar for Unhnd_Exception

I used to use the above technique with creating a Result variable.

I now put it in a Select Case.

Select Case MsgBox("I just started the process of getting wasted", MsgBoxStyle.YesNo)
 
       Case MsgBoxResult.Yes

       Case MsgBoxResult.No

End Select
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.