System.InavlidCastException Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This problably has a very simple explanation but it is totally perplexing me.
I have the following code...

Dim CompletelyUsed As String
CompletelyUsed = Me.txtCompletelyUsed.Text

Select Case CompletelyUsed
Case "Y" Or "y"
Do 'Do something here
Case "N" Or "n"
Do... 'Do something here
End Select
The problem is that when the Select Case statement is executed I get the
following error: "System.InavlidCastException: Cast from string "(the value
of Completelyused)" to type 'Long' is not valid. --->
System.FormatException: Input string was not in a correct format."

Could someone please help me understand why this error is occuring? Thanks.
 
Because you are performing an Or opperation on two strings. Try this

Case "Y", "y"

Case "N", "n"
 
Back
Top