I'm having a problem with VB on msgboxresult. when i run this code it doesn't matter which button the user presses. yes or no. it still executes both statements when i only want it to execute the one the user chooses. both prompts come up... "you clicked no" and later "you clicked yes" and the test files get deleted either way. here is the code. if anyone knows how to fix this please help thanks
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
MsgBox("Are you sure you want to permanently delete these files?", MsgBoxStyle.YesNo)
If MsgBoxResult.No Then
MsgBox("you clicked no!")
End If
If MsgBoxResult.Yes Then
MsgBox("You clicked yes!")
End If
End Sub
You have two problems here.
1) You have not defined MsgBoxResult as a return value.
2) You are using two if statements instead of using else or elseif.
You'll need to format this properly in your source as it won't be indented correctly here.
Dim Answer as MsgBoxResult = MsgBox("Are you sure you want to permanently delete these files?", MsgBoxStyle.YesNo)
Select Case Answer
Case MsgBoxResult.Yes
MsgBox("you chose yes")
Case MsgBoxResult.No
MsgBox("you chose no")
Case Else
MsgBox("you chose something else unexpected") 'could mean they hit the X on the popup. You can always remove this.
End Select
Goodluck!