none
Conversion from the string to double is failing in visual studio 2017 However the same code is working visual studio 2015 RRS feed

  • Question

  • The below snippet of code is causing the problem .it's working absolutely fine in earlier version of VS like 2015 and 2012.

    I thought i had some visual studio settings to restrict the explicit conversion so i have checked all possible config available in visual studio 2017 but i am not able to get it working.

    the problem is that my existing code have lot of code where i am converting from string to double .since its a compatible string format with correct decimal values so it should be get convert into double.

    any one face same kind of error in Visual studio 2017 ?

    your input is highly appreciated ?

     Dim result As String
    Dim Values As String = "8.07017543859649"

            result = CDbl(Values )

       
    Thursday, January 31, 2019 12:36 PM

All replies

  • Hello,

    This is the wrong forum (I will move it).

    This is done in VS2017 and works and is how the convert should be done.

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim Values As String = "8.07017543859649"
        Dim result As Double = 0
    
        If Double.TryParse(Values, result) Then
            MessageBox.Show(result.ToString())
        Else
            MessageBox.Show($"{Values} is not a vaid double")
        End If
    End Sub

    This also works for me.

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim Values As String = "8.07017543859649"
        Dim result As Double = CDbl(Values)
        MessageBox.Show(result.ToString())
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, January 31, 2019 2:29 PM
    Moderator
  • The below snippet of code is causing the problem .it's working absolutely fine in earlier version of VS like 2015 and 2012.

    I thought i had some visual studio settings to restrict the explicit conversion so i have checked all possible config available in visual studio 2017 but i am not able to get it working.

    the problem is that my existing code have lot of code where i am converting from string to double .since its a compatible string format with correct decimal values so it should be get convert into double.

    any one face same kind of error in Visual studio 2017 ?

    your input is highly appreciated ?

     Dim result As String
    Dim Values As String = "8.07017543859649"

            result = CDbl(Values )

       

    Hi

    The reason you are getting that exception is because you declared the variable 'result' as a String then tried to assign a numeric Double to it.

    Maybe try setting Option Strict On amd Option Explicit On to assist you in seeing those types of errors.


    Regards Les, Livingston, Scotland

    Thursday, January 31, 2019 2:39 PM