I am trying to display a TextChanged
result but I have an error that says:
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format.
Here is my sample code:
Public Class Form1
Dim double1 As Double = 0.0
Dim double2 As Double = 0.0
Dim result As Double = 0.0
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
double1 = TextBox1.Text
double2 = TextBox2.Text
result = Double.Parse(Label1.Text).ToString
result = double1 + double2
End Sub
I am new to this stuff. How will I fix this? Thank you for the response.
答案 0 :(得分:0)
您可以同时使用“IF”或val来解决问题。而且你没有在标签上显示任何东西。你需要它>
Label1.text = result
展示它。
Public Class Form1
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
'If Not IsNumeric(TextBox1.Text) OrElse Not IsNumeric(TextBox2.Text) Then Exit Sub
Dim double1 As Double
Dim double2 As Double
Dim result As Double
double1 = Val(TextBox1.Text)
double2 = Val(TextBox2.Text)
result = double1 + double2
Label1.Text = result
End Sub
End Class