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"
 
That's the problem! Thanks for your help - I knew it had to be something
simple.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top