Reputation: 3
Beginner here using VB2010 Express - using MessageBox.show IF/ELSEIF statements but my buttons have to be pressed several times, 1st btn once, 2nd twice, 3rd three times before the resulting message dialog box actually shows. I don't know how my Dim statements connects to this. Dim Result As ...
Private Sub btnMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMessage.Click
Dim Result As
If MessageBox.Show("Click something.", "Title", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Abort Then
MessageBox.Show("Aborted")
ElseIf MessageBox.Show("Click something", "Title", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Retry Then
MessageBox.Show("Retrying.")
ElseIf MessageBox.Show("Click something", " Title", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Ignore Then
MessageBox.Show("Ignoring.")
End If
End Sub
End Class
Upvotes: 0
Views: 137
Reputation: 5406
You are missing some very important very basic programming concepts. This is not the place to teach you those basics - that is what universities are for.
Enough to say you have three totally separate message boxes, hence they can appear three times.
The solution is to (properly) use variables:
Dim result
result = MessageBox.Show("Click something.", "Title", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question)
'store the chosen answer in the "result" variable, then use it to check the result
If result = Windows.Forms.DialogResult.Abort Then
MessageBox.Show ("Aborted")
ElseIf result = Windows.Forms.DialogResult.Retry Then
MessageBox.Show ("Retrying.")
ElseIf result = Windows.Forms.DialogResult.Ignore Then
MessageBox.Show ("Ignoring.")
End If
Upvotes: 1