Convert text to double

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

    Convert text to double

    Hello

    I want to convert a value in a text propertie to a double.

    I can use CDbl(grid1.text ) for this, but the problem is that some text
    properties are empty and when they are the code give errors.

    Is there a way to convert text to double, but if the text is empty he just
    returns zero?

    Kind Regards
    Erwin


  • B

    #2
    Re: Convert text to double

    Erwin Bormans schreef:[color=blue]
    > Hello
    >
    > I want to convert a value in a text propertie to a double.
    >
    > I can use CDbl(grid1.text ) for this, but the problem is that some text
    > properties are empty and when they are the code give errors.
    >
    > Is there a way to convert text to double, but if the text is empty he just
    > returns zero?
    >
    > Kind Regards
    > Erwin
    >
    >[/color]

    Cdbl(Val(grid1. text)), but watch out it will give zero for an empty
    string. Otherwise use if ..then

    if lenb(grid1.text ) <> 0 then
    CDbl(grid1.text )
    end if

    B.

    Comment

    • Hal Rosser

      #3
      Re: Convert text to double

      val(text1.text)
      - I believe it returns zero if empty or not a number

      "Erwin Bormans" <erwin.bormans@ verwijderdit.te lenet.be> wrote in message
      news:427735c9$0 $12978$ba620e4c @news.skynet.be ...[color=blue]
      > Hello
      >
      > I want to convert a value in a text propertie to a double.
      >
      > I can use CDbl(grid1.text ) for this, but the problem is that some text
      > properties are empty and when they are the code give errors.
      >
      > Is there a way to convert text to double, but if the text is empty he just
      > returns zero?
      >
      > Kind Regards
      > Erwin
      >
      >[/color]


      Comment

      • Jon Smyth

        #4
        Re: Convert text to double

        The best way would be to handle the error in the code. Use the 'On Local
        Error' trap to handle it within the subroutine. If you get the conversion
        error you can do whatever makes sense to your application.

        "Erwin Bormans" <erwin.bormans@ verwijderdit.te lenet.be> wrote in message
        news:427735c9$0 $12978$ba620e4c @news.skynet.be ...[color=blue]
        > Hello
        >
        > I want to convert a value in a text propertie to a double.
        >
        > I can use CDbl(grid1.text ) for this, but the problem is that some text
        > properties are empty and when they are the code give errors.
        >
        > Is there a way to convert text to double, but if the text is empty he just
        > returns zero?
        >
        > Kind Regards
        > Erwin
        >
        >[/color]


        Comment

        Working...