Tuesday, March 24, 2009

catching errors!

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim result As Integer
Dim num1, num2 As Integer
'storage!
Try
num1 = txtNum1.Text
Catch ex As Exception
MsgBox("You have to enter a number!")
txtNum1.Text = ""
txtNum1.Focus() 'bring back the user to the location
End Try
Try
num2 = txtNum2.Text
Catch ex As Exception
MsgBox("You have to enter a number!")
txtNum2.Text = ""
txtNum2.Focus()
End Try
'convert String into Integer
result = num1 + num2
'calculation!
'input within the textboxes!
lblResult.Text = result
'output with the label!
End Sub
End Class

No comments: