471,356 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

System.InavlidCastException Error

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.
Jul 21 '05 #1
2 1078
Because you are performing an Or opperation on two strings. Try this

Case "Y", "y"

Case "N", "n"

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:07**********************************@microsof t.com...
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.

Jul 21 '05 #2
That's the problem! Thanks for your help - I knew it had to be something
simple.

"JohnFol" wrote:
Because you are performing an Or opperation on two strings. Try this

Case "Y", "y"

Case "N", "n"

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:07**********************************@microsof t.com...
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.


Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Martin Honnen | last post: by
8 posts views Thread by A P | last post: by
2 posts views Thread by MrMike | last post: by
2 posts views Thread by BruceWho | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.