Page 133 - TCS ICT Book 8
P. 133
The City School 2021-2022
Program Debugging and Error Handling
Public Class Form1
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnCalculate.Click Appendix
lbl_errorMsg.Visible = False
Dim firstNum, secondNum As Double
On Error GoTo error_handler
firstNum = firstNumber.Text
secondNum = secondNumber.Text
lblAnswer.Text = firstNum / secondNum
Exit Sub
‘to prevent error handling even when inputs are valid’
error_handler:
lblAnswer.Text = “Error”
lbl_errorMsg.Visible = True
lbl_errorMsg.Text = “One of the the entries is not a Number! Try
again”
End Sub
End Class
133

