Converting string to long

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

How can I convert a string to long value? Most objects have a toString
method but strings don't have a toLong method.

Thanks

Regards
 
John said:
Hi

How can I convert a string to long value? Most objects have a
toString method but strings don't have a toLong method.


dim l as long
l = long.parse("123456")
 
Or I guest to be more .nettie CType(object, Long)

Bryan Martin ;)
(e-mail address removed)
 
Hi,

Dim myStr As String = "1001"

Dim myLng As Long

Try

myLng = CType(myStr, Long)

Catch ex As Exception

MessageBox.Show(ex.ToString)

End Try

Ken
 
* "John said:
How can I convert a string to long value? Most objects have a toString
method but strings don't have a toLong method.

\\\
Dim n As Long = Long.Parse(<string>)
///
 
Hi John,

|| .. strings don't have a toLong method

True, fortunately Longs (in fact all the numeric types) have
a 'from-string' method except that it's called Parse. You'll
find that it's very unforgiving, unlike the old VB Val function.

You can still use Val.

For the full whack - look up topic: Parsing Numeric Strings

Regards,
Fergus
 
Stop spamming Herfried.

You're a bore.

You're a hypocrite.

You're a condescending <deleted>.

You're a PLS.
 
Hi

How can I convert a string to long value? Most objects have a toString
method but strings don't have a toLong method.

Thanks

Regards

Well, you got a lot of answers, but nobody posted:

Dim l As Long = System.Convert.ToInt64("1234")
 
Is it just me or does anyone else think that Fergus and Herfried are
in fact the same person. I believe one of them posts a response and
then immediately replies to himself using a different guise and a
caustic reply. It has to be this because the alternative is that we
have two informed people publically showing how childish each can be.

Both of you, grow up!

Monty
 
Tom Shelton said:
Well, you got a lot of answers, but nobody posted:

Dim l As Long = System.Convert.ToInt64("1234")

System.Convert.ToInt64 calls System.Int64.Parse (= Long.Parse)

:-)
 
* "Monty said:
Is it just me or does anyone else think that Fergus and Herfried are
in fact the same person.

I am not Fergus.

Remember:

"
Dilbert's words of wisdom #18: Never argue with an idiot.
They drag you down to their level then beat you with experience.
"

I was dragged down some weeks ago.
 
Back
Top