Reputation: 194
How do you give output based on MessageBox input?
ie. I have a application which shows a MessageBox on button click. The MessageBox has buttons Abort, Retry, and Ignore.
I want to make it so on clicking each button, I want to display a MessageBox with different text.
Eg: On clicking Abort, I want to display a MessageBox with text "Aborted".
On clicking Retry, I want to display a MessageBox with text "Retried".
On clicking Ignore, I want to display a MessageBox with text "Ignored".
My attempt was: (I get a error: A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll.
Additional information: Conversion from string "Input" to type 'Integer' is not valid.
If there is a handler for this exception, the program may be safely continued.)
Public Class Form1
Private Sub Input_Click(sender As Object, e As EventArgs) Handles Input.Click
Dim a As DialogResult = MsgBox("Click anything.", "Input", MessageBoxButtons.AbortRetryIgnore)
Select Case a
Case Windows.Forms.DialogResult.Abort
MsgBox("Aborted", "Abort")
Case Windows.Forms.DialogResult.Retry
MsgBox("Retried", "Retry")
Case Windows.Forms.DialogResult.Ignore
MsgBox("Ignored", "Ignore")
End Select
End Sub
End Class
PS: Use of Select Case would be preferred.
Upvotes: 0
Views: 1135
Reputation: 884
Here you go mate.
Dim a As DialogResult = MessageBox.Show("Click anything.", "Input", MessageBoxButtons.AbortRetryIgnore)
Select Case a
Case Windows.Forms.DialogResult.Abort
Console.WriteLine("Aborted")
Case Windows.Forms.DialogResult.Cancel
Console.WriteLine("Cancel")
End Select
Upvotes: 1