locked
CDbl function RRS feed

  • Question

  • In Visual Basic 2008

     

    Dim x_string As String

    x_string = "(2)"

    CDbl(x_string) yields -2

     

    Is that correct?

    Monday, July 28, 2008 10:01 PM

All replies

  • Another CDbl problem
     
    CDbl("12.3") returns "type mismatch" error
     
    ??
     
    Tuesday, August 5, 2008 8:33 AM
  •  

    point 1, yes that is correct, surrounding a number by brackets means it will get evaluated as negative.  If thats a problem strip out the ( and ) like so

     

    Dim x_string As String

    Dim x As Double

    x_string = "(2)"

    x = CDbl(x_string.Replace("(", "").Replace(")", ""))

     

    point 2 doesn't give type mismatch at all eg. this works fine :-

     

    Dim x As Double

    x = CDbl("12.3")

    Thursday, October 23, 2008 3:39 PM