Visual basic 2003: Convert 'String' to 'Double'

Posted on 2006-04-09
Last Modified: 2013-11-25
I'm trying to do deployment with strict on.
However, editstudCourse Fee.text is giving me error="option strict on disallows implicit conversions from string to double."
Hope someone can shed some light on this.

    Dim TaxValue As Double = 5
    Dim TaxValueContainer As String

    Dim courseFee As Double = 0
    Dim courseFeeContainer As String

    Dim TaxDisplay As Double
    Dim TaxValueInput As Double
    'Dim noContainer As String
    Dim no1, no2, no3, no4 As Double


   editstudTaxAmount.Text = editstudCourseFee.Text * TaxValue / 100   <--How to convert editstudCourseFee.Text from 'string' to 'double'
            no1 = Double.Parse(editstudCourseFee.Text)
            no2 = Double.Parse(editstudTaxAmount.Text)
            editstudTotalPayable.Text = Round(no1 + no2, 2).ToString

            no3 = Double.Parse(editstudTotalPayable.Text)
            no4 = Double.Parse(editstudTotalPaid.Text)
            editstudTotalBalance.Text = Round(no3 - no4).ToString
Question by:dandeliondream
    LVL 44

    Expert Comment

    Hello werD420,

    you can use
    editstudTaxAmount.Text = Convert.ToDouble(editstudCourseFee.Text) * TaxValue / 100

    but why are you converting to double on the next line?

    hope this helps a bit
    LVL 44

    Accepted Solution

    and you probably need to reconvert after the calculation
    editstudTaxAmount.Text = Convert.ToString(Convert.ToDouble(editstudCourseFee.Text) * TaxValue / 100)
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Be sure to enclose any of your conversion calls that involve a string to a number data type in a Try...Catch block.  Otherwise your application will crash if the string contains a value that cannot be converted to a valid number.
    LVL 3

    Author Comment

    Problem solved. A big thankQ to bruintje and Idle_Mind.
    LVL 44

    Expert Comment

    you're welcome :)

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now