InvalidCastException

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

Why can't I cast a number from a textbox into a long? Whenever I try
to do it, I get "InvalidCastException" If I can't do that, how am I
supposed to get a textbox's text cast into a Long?

Thanks
 
Why can't I cast a number from a textbox into a long? Whenever I try
to do it, I get "InvalidCastException"
Please read one of the many resources on casting and where it applies.
If I can't do that, how am I
supposed to get a textbox's text cast into a Long?
Convert.ToInt64() or Int64.Parse()

Cheers
Daniel
 
Aaron said:
Why can't I cast a number from a textbox into a long? Whenever I try
to do it, I get "InvalidCastException" If I can't do that, how am I
supposed to get a textbox's text cast into a Long?

Thanks

Aaron, You can use any of the 3 options

Dim dStr as Long

a. dStr=CLng(TextBox1.Text) or
b. dStr=Convert.Int64(TextBox1.Text) or
c. dStr=Long.Parse(TextBox1.Text)
 
Back
Top