.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CDbl in 2008 and 2011

8 REPLIES 8
Reply
Message 1 of 9
hericson
675 Views, 8 Replies

CDbl in 2008 and 2011

I want to convert a string to double and I'm using CDbl instead of Val because it can handle values with an exponent. But now I found out what it will give different results depending on AutoCAD 2008 or AutoCAD 2011. For example:

CDbl("12.345") => 12345 in 2008

CDbl("12,345") => 12,345 in 2008

CDbl("12.345") => 12.345 in 2011

CDbl("12,345") => 12345 in 2011

AutoCAD 2008 runs on swedish Windows XP Pro and AutoCAD 2011 on swedish Windows 7 Pro. Can it have something to do with differences in .NET or what is it?

8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: hericson

Did you check your Windows Regional settings ?

or use this kind of (VB6) procedures


Public Function Str2Num(ByVal val As Variant) As Double
    Dim x As String
    Dim decSep As String
       
    decSep = GetLocalDecimalChar
    Select Case decSep
    Case "."
        val = replace(val, ",", ".")
    Case ","
        val = replace(val, ".", ",")
    End Select
    On Error Resume Next
    Str2Num = val

End Function

Public Function GetLocalDecimalChar() As String
   GetLocalDecimalChar = Mid$(CStr(3.3), 2, 1)
End Function

Message 3 of 9
Anonymous
in reply to: hericson

You could look into the Format function.

 

Regards,

Message 4 of 9
hericson
in reply to: hericson

I don't think it has to do with Windows settings. Today I tested on an old computer with Autocad 2006, 2007, 2008 and 2010 installed. I made a test and ran it in all installed Autocad's and I have attached the result. 2006-2008 does it in one way and 2010 (like 2011) in another way, which I prefer. It must be something with AutoCAD or .NET

Message 5 of 9
Anonymous
in reply to: hericson

Cdbl is a .Net command.  AutoCAD's dlls should not have any affect.  Although... older autocads targeted older .net frameworks.  AutoCAD 2010 targets 3.5, and AutoCAD 2011 targets 3.5, but supports 4.0 as well.

 

jvj 

 

(when did I learn all this junk, I just wanted to be a musician when I grew up.)

Message 6 of 9
Anonymous
in reply to: hericson

Is the result of this test different for these configurations ?

 
    '   Imports System.Globalization
    <CommandMethod("DecimalChar")> _
    Public Sub DecimalChar()
        Dim separatorFormat As New NumberFormatInfo()
        If NumberFormatInfo.CurrentInfo.NumberDecimalSeparator = "," Then
            Debug.WriteLine("',' as Decmal Seperator")
        Else
            Debug.WriteLine("'.' as Decmal Seperator")
        End If
    End Sub

Message 7 of 9
hericson
in reply to: Anonymous

The result is a dot ( . ) in AutoCAD 2011 and a comma ( , ) in AutoCAD 2008. I haven't yet tested it on the computer with 2006, 2007, 2008 and 2010.

Message 8 of 9
Anonymous
in reply to: hericson

So this would be more a .NET problem dan an AutoCAD problem to me.

I have seen this before in VB6 and there for i used the function to see what VB uses when converting to strings and then replace  the decimal char in  numeric User/File  input to that character before converting.

Have not any problem again.

 

Message 9 of 9
hericson
in reply to: Anonymous

That's my solution to the problem as well, I did my own function StrToDouble to solve the conversion.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost