Solved

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

Posted on 2006-04-09
435 Views
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

...continue

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
0
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
bruintje
0

LVL 44

Accepted Solution

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

LVL 85

Expert Comment

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.
0

LVL 3

Author Comment

Problem solved. A big thankQ to bruintje and Idle_Mind.
0

LVL 44

Expert Comment

you're welcome :)
0

## Featured Post

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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…