Am using program which must treat user input differently, depends whether on number or string. Select Case and IsNumeric are not working as expected.
I get this code when animal=a char or string.
Error:
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Additional information: Conversion from string "D" to type 'Long' is not valid.
Code which troubles:
Case "D" Or "d"
All of code:
Option Explicit Off
Option Strict Off
Public Class MainForm
Public Sub ifButton_Click(sender As Object, e As EventArgs) Handles ifButton.Click
animal = codeTextBox.Text
Select Case IsNumeric(codeTextBox.Text)
Case True
Dim decanimal As Decimal
decanimal = CDec(animal)
Select Case decanimal
Case "1"
msgLabel.Text = "Dog"
Case "2"
msgLabel.Text = "Cat"
Case Else
msgLabel.Text = "Bird"
End Select
Case False
Dim stranimal As String
stranimal = CStr(animal)
Select Case stranimal
Case "D" Or "d"
msgLabel.Text = "Dog"
Case "C" Or "c"
msgLabel.Text = "Cat"
Case Else
End Select
End Select
End Sub
End Class