Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

4.2 VB.net String to double conversion


  • Please log in to reply
6 replies to this topic

#1 Bainesbunch

Bainesbunch

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts
  • LocationFrance

Posted 16 January 2012 - 03:12 PM

Hello Folks,

I am having some issues converting a string into a double using the CDbl(...) method. It is throwing a System.NotImplementedException.

How do we convert a string into a double without this method ?

I have a configuration file stored on the SD card where i save and retrieve values in an eye readable format so that the user can "edit" them in notepad etc. I.E. 100,10.000,2.5,6 these need to be read back into the application and converted into either bytes integers doubles etc. any help gratefully received.

the offending code looks like this


dim ErectParkDecerlationPoint as double = CDbl("10.000")


Here is the output trace for the call.



Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.IsHexOrOctValue'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.IsHexOrOctValue'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.IsHexOrOctValue'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetCultureInfo'
Step into: Stepping over non-user code 'System.Globalization.CultureInfo.CurrentUICulture.get'
Step into: Stepping over non-user code 'System.Globalization.CultureInfo.CurrentUICulture.get'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetCultureInfo'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble'
Step into: Stepping over non-user code 'System.Globalization.CultureInfo.NumberFormat.get'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat'
Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberDecimalSeparator.get'
Step into: Stepping over non-user code 'System.Globalization.CultureInfo.EnsureStringResource'
Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberDecimalSeparator.get'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat'
Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberGroupSeparator.get'
Step into: Stepping over non-user code 'System.Globalization.CultureInfo.EnsureStringResource'
Step into: Stepping over non-user code 'System.Resources.ResourceManager.GetObjectFromId'
Step into: Stepping over non-user code 'System.Resources.ResourceManager.GetObjectFromId'
Step into: Stepping over non-user code 'System.Globalization.CultureInfo.EnsureStringResource'
Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberGroupSeparator.get'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat'
Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberDecimalSeparator.get'
Step into: Stepping over non-user code 'System.Globalization.CultureInfo.EnsureStringResource'
Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberDecimalSeparator.get'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat'
Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberGroupSeparator.get'
Step into: Stepping over non-user code 'System.Globalization.CultureInfo.EnsureStringResource'
Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberGroupSeparator.get'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ToHalfwidthNumbers'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble'
Step into: Stepping over non-user code 'double.Parse'
Step into: Stepping over non-user code 'System.Convert.ToDouble'
Step into: Stepping over non-user code 'System.Convert.ToDouble'
Step into: Stepping over non-user code 'System.Convert.ToDouble'
Step into: Stepping over non-user code 'System.Convert.ToDouble'
Step into: Stepping over non-user code 'System.Convert.ToDouble'
Step into: Stepping over non-user code 'System.Convert.ToDouble'
Step into: Stepping over non-user code 'System.Convert.ToDouble'
Step into: Stepping over non-user code 'System.Convert.GetDoubleNumber'
Step into: Stepping over non-user code 'System.Convert.ToDouble'
A first chance exception of type 'System.NotImplementedException' occurred in mscorlib.dll
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble'
A first chance exception of type 'System.NotImplementedException' occurred in Microsoft.VisualBasic.dll
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble'
Step into: Stepping over non-user code 'System.Exception.Message.get'
Step into: Stepping over non-user code 'System.Exception.Message.get'
Step into: Stepping over non-user code 'System.Exception.Message.get'
Step into: Stepping over non-user code 'System.Exception.Message.get'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble'
Step into: Stepping over non-user code 'System.InvalidCastException.InvalidCastException'
Step into: Stepping over non-user code 'System.SystemException.SystemException'
Step into: Stepping over non-user code 'System.Exception.Exception'
Step into: Stepping over non-user code 'System.Exception.Exception'
Step into: Stepping over non-user code 'System.SystemException.SystemException'
Step into: Stepping over non-user code 'System.InvalidCastException.InvalidCastException'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble'
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Step into: Stepping over non-user code 'System.IO.TextReader.Dispose'
Step into: Stepping over non-user code 'System.IO.StreamReader.Dispose'
Step into: Stepping over non-user code 'System.IO.Stream.Close'
Step into: Stepping over non-user code 'System.IO.FileStream.Dispose'
Step into: Stepping over non-user code 'System.IO.FileStream.Dispose'
Step into: Stepping over non-user code 'System.IO.FileSystemManager.RemoveFromOpenList'
Step into: Stepping over non-user code 'System.IO.FileSystemManager.RemoveFromOpenList'
Step into: Stepping over non-user code 'System.Collections.ArrayList.Remove'
Step into: Stepping over non-user code 'System.Array.IndexOf'
Step into: Stepping over non-user code 'System.Array.IndexOf'
Step into: Stepping over non-user code 'System.Collections.ArrayList.Remove'
Step into: Stepping over non-user code 'System.Collections.ArrayList.Remove'
Step into: Stepping over non-user code 'System.IO.FileSystemManager.RemoveFromOpenList'
Step into: Stepping over non-user code 'System.IO.FileStream.Dispose'
Step into: Stepping over non-user code 'System.IO.Stream.Close'
Step into: Stepping over non-user code 'System.IO.Stream.Close'
Step into: Stepping over non-user code 'System.IO.StreamReader.Dispose'
Step into: Stepping over non-user code 'System.IO.TextReader.Dispose'
Step into: Stepping over non-user code 'System.IO.TextReader.Dispose'
Step into: Stepping over non-user code 'System.IO.Stream.Dispose'
Step into: Stepping over non-user code 'System.IO.Stream.Close'
Step into: Stepping over non-user code 'System.IO.FileStream.Dispose'
Step into: Stepping over non-user code 'System.IO.Stream.Close'
Step into: Stepping over non-user code 'System.IO.Stream.Close'
Step into: Stepping over non-user code 'System.IO.Stream.Dispose'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.ProjectData.SetProjectError'


I was going to change the world, then I discovered Netduino.
The world will have to wait.

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 16 January 2012 - 03:49 PM

Hi Bainesbunch, This appears to be a bug in the emulated floating point library for .NET MF 4.2. Could you please post a bug report (or vote for it, if already posted) at netmf.codeplex.com? And then hopefully we can get a bugfix for it checked in soon? Thank you, Chris

#3 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 16 January 2012 - 07:32 PM

CDbl works for me in MF 4.2 RC1
Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoPlus
Module Module1
    Sub Main()
        Dim ErectParkDecerlationPoint As Double = CDbl("10.000")
        Debug.Print("ErectParkDecerlationPoint = " & ErectParkDecerlationPoint.ToString) '--> ErectParkDecerlationPoint = 10
        Dim a As Double = CDbl("12345.6789")
        Debug.Print("a = " & a.ToString) 'a = 12345.678900000001
        Dim b As Double = CDbl("166511.001e9")
        Debug.Print("b = " & b.ToString) 'b = 166511.00099999999
    End Sub
End Module
I have not experienced many of the problems reported for RC3 using RC1. It might be worthwhile to revert back until these problems are solved.

Baxter

#4 Bainesbunch

Bainesbunch

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts
  • LocationFrance

Posted 16 January 2012 - 07:51 PM

CDbl works for me in MF 4.2 RC1

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoPlus
Module Module1
    Sub Main()
        Dim ErectParkDecerlationPoint As Double = CDbl("10.000")
        Debug.Print("ErectParkDecerlationPoint = " & ErectParkDecerlationPoint.ToString) '--> ErectParkDecerlationPoint = 10
        Dim a As Double = CDbl("12345.6789")
        Debug.Print("a = " & a.ToString) 'a = 12345.678900000001
        Dim b As Double = CDbl("166511.001e9")
        Debug.Print("b = " & b.ToString) 'b = 166511.00099999999
    End Sub
End Module
I have not experienced many of the problems reported for RC3 using RC1. It might be worthwhile to revert back until these problems are solved.

Baxter


OK so where do I get 4.2 RC1 from for the plus for me to try this out please

A link would be good if you have one.

Cheers Pete
I was going to change the world, then I discovered Netduino.
The world will have to wait.

#5 Bainesbunch

Bainesbunch

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts
  • LocationFrance

Posted 16 January 2012 - 08:11 PM

Actualy the plot thickens. This code works on the emulator but NOT on the device .. what is going on here ????



Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoPlus
Module Module1
    Sub Main()
        Dim ErectParkDecerlationPoint As Double = CDbl("10.000")
        Debug.Print("ErectParkDecerlationPoint = " & ErectParkDecerlationPoint.ToString) '--> ErectParkDecerlationPoint = 10
        Dim a As Double = CDbl("12345.6789")
        Debug.Print("a = " & a.ToString) 'a = 12345.678900000001
        Dim b As Double = CDbl("166511.001e9")
        Debug.Print("b = " & b.ToString) 'b = 166511.00099999999
    End Sub
End Module

I was going to change the world, then I discovered Netduino.
The world will have to wait.

#6 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 16 January 2012 - 09:10 PM

Actualy the plot thickens. This code works on the emulator but NOT on the device .. what is going on here ????


Actually, I don't think that's surprising at all. I believe that with 4.2 RC3, the firmware was built to use new emulated floating point methods. This was done (I think) because the Netduino's Atmel processor does not have support for some of the higher level functions (like log). Unfortunately, it had some issues and as a side-effect, broke the functions for parsing strings into numeric floating point types. I believe the integer methods do work in 4.2 RC3. Since this is specific to this version of the firmware, it would not have impacted the emulator functioning properly. That's what I believe is going on.

Honestly, I just work around it. If you want to work around this, you can write your own function that iterates through the digits, multiply by the appropriate power of 10 and accumulate the sum in a float... When working on the cutting edge, you'll find working around things is sometimes necessary...

Eventually though, I'm sure this will get fixed.

-Valkyrie-MT

#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 17 January 2012 - 03:02 AM

Between RC1 (based on .NET MF 4.2 RC) and RC3 (based on .NET MF 4.2 RTM), the default .NET MF firmware seems to have grown by several 10KB in size...which I believe is probably why the floating point support was switched from standard to emulated floating point. We're hoping that the bugs in the emulated floating point library can get fixed in a reasonably quick fashion. If not, there may be a way to cut out the last-minute additions so we can fit the old floating point library back in... Chris




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.