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?
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
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
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.)
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
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.
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.