You should always check the user inputs. A proper validation should be done before doing the actual operation.
It's better to use Integer.TryParse() method to "try" converting the value from the TextBoxes to an Integer value.
Here's the example:
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'~~~ Declaring the variables
Dim num1 As Integer
Dim num2 As Integer
Dim result As Integer
If Integer.TryParse(TextBox1.Text, num1) Then '~~~ we are trying to convert the value of 'TextBox1' to Integer value. If success, the value would be stored in 'num1' variable.
If Integer.TryParse(TextBox2.Text, num2) Then '~~~ Now, we are going after the second value. That is, trying to convert the value of 'TextBox2' to Integer value. If success, the value would be stored in 'num2' variable.
result = num1 + num2 '~~~ we got the two values. So, we are adding them and storing the result in the variable named 'result'
'~~~ Now displaying the result
MessageBox.Show(String.Format("{0} + {1} = {2}", num1.ToString, num2.ToString, result.ToString)) '~~~ We are going to display the result in a MessageBox. We are using String.Format() function to format the string with placeholders.
Else '~~~ if the conversion of value from "TextBox2" to Integer fails..
MessageBox.Show("Second number should be a valid integer !", "Error")
End If
Else '~~~ if the conversion of value from "TextBox1" to Integer fails..
MessageBox.Show("First number should be a valid integer !", "Error")
End If
End Sub
End Class