Converting string to long

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Converting string to long

    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


  • Bryan Martin

    #2
    Re: Converting string to long

    Or I guest to be more .nettie CType(object, Long)

    Bryan Martin ;)
    Spam@ahwayside. com

    "John" <john@nospam.in fovis.co.uk> wrote in message
    news:%235SkrXlp DHA.2232@TK2MSF TNGP09.phx.gbl. ..[color=blue]
    > 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
    >
    >[/color]


    Comment

    • Bryan Martin

      #3
      Re: Converting string to long

      CLng(AObject)

      Is this what your after

      "John" <john@nospam.in fovis.co.uk> wrote in message
      news:%235SkrXlp DHA.2232@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > 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
      >
      >[/color]


      Comment

      • Adrian Forbes [ASP MVP]

        #4
        Re: Converting string to long

        Use the Parse method

        int32.Parse ("123)

        "John" <john@nospam.in fovis.co.uk> wrote in message
        news:%235SkrXlp DHA.2232@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        > 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
        >
        >[/color]


        Comment

        • Ken Tucker [MVP]

          #5
          Re: Converting string to long

          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" <john@nospam.in fovis.co.uk> wrote in message
          news:%235SkrXlp DHA.2232@TK2MSF TNGP09.phx.gbl. ..[color=blue]
          > 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
          >
          >[/color]


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Converting string to long

            * "John" <john@nospam.in fovis.co.uk> scripsit:[color=blue]
            > How can I convert a string to long value? Most objects have a toString
            > method but strings don't have a toLong method.[/color]

            \\\
            Dim n As Long = Long.Parse(<str ing>)
            ///

            --
            Herfried K. Wagner
            MVP · VB Classic, VB.NET
            <http://www.mvps.org/dotnet>

            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: Converting string to long

              * "Adrian Forbes [ASP MVP]" <sorry@noemail. zzz> scripsit:[color=blue]
              > Use the Parse method
              >
              > int32.Parse ("123)[/color]

              'Int32' isn't a 'Long'.

              ;-)))

              --
              Herfried K. Wagner
              MVP · VB Classic, VB.NET
              <http://www.mvps.org/dotnet>

              Comment

              • Fergus Cooney

                #8
                Re: Converting string to long

                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


                Comment

                • Herfried K. Wagner [MVP]

                  #9
                  Re: Converting string to long

                  * "Fergus Cooney" <filter@post.co m> scripsit:[color=blue]
                  > For the full whack - look up topic: Parsing Numeric Strings[/color]

                  Where to look up for this topic?

                  --
                  Herfried K. Wagner
                  MVP · VB Classic, VB.NET
                  <http://www.mvps.org/dotnet>

                  Comment

                  • Fergus Cooney

                    #10
                    Re: Converting string to long




                    Comment

                    • Fergus Cooney

                      #11
                      Re: Converting string to long

                      Add OT to your irrelevant posts unless

                      you want to be seen as a hypocrite.


                      Comment

                      • Herfried K. Wagner [MVP]

                        #12
                        OT: Re: Converting string to long

                        * "Fergus Cooney" <filter@post.co m> scripsit:[color=blue]
                        > Add OT to your irrelevant posts unless
                        >
                        > you want to be seen as a hypocrite.[/color]

                        Rules of Conduct
                        <http://www.microsoft.c om/communities/conduct/default.mspx>

                        --
                        Herfried K. Wagner
                        MVP · VB Classic, VB.NET
                        <http://www.mvps.org/dotnet>

                        Comment

                        • Fergus Cooney

                          #13
                          Re: Re: Converting string to long

                          Stop spamming Herfried.

                          You're a bore.

                          You're a hypocrite.

                          You're a condescending <deleted>.

                          You're a PLS.


                          Comment

                          • Armin Zingler

                            #14
                            Re: Converting string to long

                            "John" <john@nospam.in fovis.co.uk> schrieb[color=blue]
                            > Hi
                            >
                            > How can I convert a string to long value? Most objects have a
                            > toString method but strings don't have a toLong method.[/color]


                            dim l as long
                            l = long.parse("123 456")


                            --
                            Armin

                            Comment

                            • Tom Shelton

                              #15
                              Re: Converting string to long

                              On 2003-11-09, John <john@nospam.in fovis.co.uk> wrote:[color=blue]
                              > 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
                              >
                              >[/color]

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

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

                              --
                              Tom Shelton
                              MVP [Visual Basic]

                              Comment

                              Working...