Converting string to Double?

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

    Converting string to Double?

    Hi

    I'm just trying to convert a small program that was written in VB6 to
    VB.Net.

    I'm stumbling at the first hurdle!

    In VB I could do the following (ensuring that the textbox only contained
    numeric input of course)...

    Dim MyNumber as Double
    MyNumber = CDbl(MyNumericT extString.text)

    and that would work fine.

    Vb.Net won't let me do the above. What do I use instead????

  • Jaap Bos

    #2
    Re: Converting string to Double?


    "J" <NoEmail@NoEmai l.comschreef in bericht
    news:85C71ECE-9CE9-44E2-9F20-1F836D00FF94@mi crosoft.com...
    Hi
    >
    I'm just trying to convert a small program that was written in VB6 to
    VB.Net.
    >
    I'm stumbling at the first hurdle!
    >
    In VB I could do the following (ensuring that the textbox only contained
    numeric input of course)...
    >
    Dim MyNumber as Double
    MyNumber = CDbl(MyNumericT extString.text)
    >
    and that would work fine.
    >
    Vb.Net won't let me do the above. What do I use instead????
    Strange, your example works without a problem for me (VB Express 2005). I
    assume that .text is an email-typo, should be .Text, but normally the
    program would make the change automatically if you type .text.
    Precisely "what" does not work when you use your program?

    Jaap


    Comment

    • Charles Law

      #3
      Re: Converting string to Double?

      Hi J

      Have a look at

      Double.Parse(.. .)

      and

      Double.TryParse (...)

      HTH

      Charles


      "J" <NoEmail@NoEmai l.comwrote in message
      news:85C71ECE-9CE9-44E2-9F20-1F836D00FF94@mi crosoft.com...
      Hi
      >
      I'm just trying to convert a small program that was written in VB6 to
      VB.Net.
      >
      I'm stumbling at the first hurdle!
      >
      In VB I could do the following (ensuring that the textbox only contained
      numeric input of course)...
      >
      Dim MyNumber as Double
      MyNumber = CDbl(MyNumericT extString.text)
      >
      and that would work fine.
      >
      Vb.Net won't let me do the above. What do I use instead????

      Comment

      • Armin Zingler

        #4
        Re: Converting string to Double?

        "J" <NoEmail@NoEmai l.comschrieb
        Hi
        >
        I'm just trying to convert a small program that was written in VB6
        to VB.Net.
        >
        I'm stumbling at the first hurdle!
        >
        In VB I could do the following (ensuring that the textbox only
        contained numeric input of course)...
        >
        Dim MyNumber as Double
        MyNumber = CDbl(MyNumericT extString.text)
        >
        and that would work fine.
        >
        Vb.Net won't let me do the above.
        Why? Error message? What is the value of MyNumericTextSt ring.text? What is
        the current culture setting? The input format must be compliant to the
        current culture settings for numeric inputs.

        What do I use instead????
        If MyNumericTextSt ring is a textbox containing "12345", it does work here.


        Armin

        Comment

        • Jem

          #5
          Re: Converting string to Double?

          Ahhh.. On further investigation it only errors if the textbox contains a
          null string, and obviously it can't convert that to a double. This was
          obviously a fault that was in the original program as well. I've error
          trapped it now and everything seems fine, sorry for that.
          J


          "Charles Law" <blank@nowhere. comwrote in message
          news:u$UgfANCIH A.4752@TK2MSFTN GP04.phx.gbl...
          Hi J
          >
          Have a look at
          >
          Double.Parse(.. .)
          >
          and
          >
          Double.TryParse (...)
          >
          HTH
          >
          Charles
          >
          >
          "J" <NoEmail@NoEmai l.comwrote in message
          news:85C71ECE-9CE9-44E2-9F20-1F836D00FF94@mi crosoft.com...
          >Hi
          >>
          >I'm just trying to convert a small program that was written in VB6 to
          >VB.Net.
          >>
          >I'm stumbling at the first hurdle!
          >>
          >In VB I could do the following (ensuring that the textbox only contained
          >numeric input of course)...
          >>
          >Dim MyNumber as Double
          >MyNumber = CDbl(MyNumericT extString.text)
          >>
          >and that would work fine.
          >>
          >Vb.Net won't let me do the above. What do I use instead????
          >
          >

          Comment

          • Cor Ligthert[MVP]

            #6
            Re: Converting string to Double?

            J,

            Those things you can test in the way as Armin and Jaap wrote.

            Just

            Dim myDouble as Double = CDbl("12345")

            Cor

            Comment

            • Cor Ligthert[MVP]

              #7
              Re: Converting string to Double?

              Charles,

              Now I see your message, it was not that javascrip.

              I was explaining somebody about the Queue class. Now I hear that you are
              back in civilisation that quarter felt in the right place.

              (Although we don't have a quarter anymore here in Holland).

              :-)

              Cor

              Comment

              • \(O\)enone

                #8
                Re: Converting string to Double?

                Cor Ligthert[MVP] wrote:
                Why not use that so nice CDbl from VB.Net, it is something I really
                miss in C#.
                You could always add a reference to Microsoft.Visua lBasic from your C#
                project, then you can use all the nice ol' VB functions such as this in your
                C# project without needing to rewrite them..?

                --

                (O)enone


                Comment

                Working...