I need to convert the data entered into a textfield on a form to Double. I have the following code:
dim dA As Double
dim dB As Double
dim dLinearFeet As Double
dim dSquareFeet As Double
dim dAcres As Double
dA = CType(tfA.Text, Double)
dB = CType(tfB.Text, Double)
dSquareFeet = dA * dB
tfSquareFeet.Text = Str(dSquareFeet)
But on compile I get:
Type mismatch error. Expected Double, but got String
dA = CType(tfA.Text, Double)
So how is the best way to convert string to double???
[quote]Use Val if you control the string that is passed, and use CDbl if the string comes from the user.
You should use CDbl instead of Val if the string contains separators.[/quote]
dim dA As Double
dim dB As Double
dim dLinearFeet As Double
dim dSquareFeet As Double
dim dAcres As Double
dA = CDbl(tfA.Text)
dB = CDbl(tfB.Text)