hello!
i have this code

Private Sub rb_W_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rb_W.CheckedChanged
Dim opt As Integer, d As Integer
opt = Int(Me.TXT_r.Text) - 110
If Me.TXT_v.Text = opt Then
Me.lbl_res.Text = ("Excellent")
End If
If Me.TXT_v.Text < opt Then
d = opt - Me.TXT_v.Text
Me.lbl_res.Text = ("Not at all")
Me.TXT_kg.Text = (d)
Else
d = Me.TXT_v.Text - opt

Me.lbl_res.Text = ("You need in")
Me.TXT_kg.Text = (d)
End If

End Sub
It calculate all right.
But by click button "Clear", when debuger reach this line
Me.rb_W.Checked = False 'where rb_W - radiobutton
occure error
Unprocessed exception of type "System.InvalidCastException" occered in Microsoft.visualbasic.dll
conversion of line "" to type Double is invalid.
and VB is pointing on
opt = Int(Me.TXT_r.Text) - 110
What's wrong?

check the value of "Me.TXT_r.Text" as even with a Int(Me.TXT_r.Text)

"" and letters cannot be converted into numbers

Try adding a "If IsNumeric(Me.TXT_r.Text) Then" to stop the Exception

i think peter was given the solution.
opt = Int(Me.TXT_r.Text) - 110
character can't be converted into numeric (int in your project)

try to make exception (try-catch) or you can stinted input in text box, if user input character or letter you can display error message.

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.