Question error shown in code,

iweir

New member
Joined
May 30, 2012
Messages
1
Programming Experience
Beginner
hi there, i am new to coding, and have came across an error with a line of my code, i have narrowed it down to this:

If TxtAnswer.Text = Answer Then
Point = Point + 1
MessageBox.Show("Correct")
Answer = Num1 + Num2
End If

it is throwing up an error saying
"InvalidCastException was Unhandled
Conversion from string "" to type 'Double' is not valid."

i have no idea what it is meaning.any help would be greatly appreciated
 
If Answer is a number then it cannot be compared directly to a String, which the Text of a TextBox is. One of them has to be converted and if the TextBox is empty then when the system tries to convert it to a number it will fail. You need to validate your data before using it and/or perform the appropriate conversions explicitly. You should start by turning Option Strict On, which won't allow you to make implicit conversions like that. It will make your code more robust and give you a better understanding of what's actually happening.
 
Back
Top