This is how you can do it without a Dim
, using MessageBox.Show
instead of MsgBox
. This is in my opinion the cleanest way of writing it!
Select Case MessageBox.Show("Message", "Title", MessageBoxButtons.YesNo)
Case vbYes
' Other Code goes here
Case vbNo
' Other Code goes here
End Select
You can shorten it down even further by using If
:
If MessageBox.Show("Message", "Title", MessageBoxButtons.YesNo) = vbYes Then
' Other Code goes here
End If