Shane Partridge
Visual Basic 2013
The Code
Public Class Form93
Private Sub MathArgument_Click(sender As Object, e As EventArgs) Handles Button1.Click
'## Error Handling Routine ------------------------------------##
'## Declare Lbl_ErrMsg as [Visible = False] ----------------------##
'## When Error is declared by [On Error Goto] ------------------- ##
'## Control is diverted to [error_handler] Routine --------------- ##
'## Lbl_ErrMsg is declared as [Visible = True] ------------------- ##
'## Value of Lbl_ErrMsg.Text is then Visible ---------------------##
'## If On Error Goto is not Declared -----------------------------##
'## Then Lbl_ErrMsg is declared as [Visible = False] = Invisible. ----##
'## Declaring Error Breach --------------------------------------##
'## Declaring Variable Lbl_ErrMsg as Invisible --------------------##
Lbl_ErrMsg.Visible = False
'## Declare Variables as Double Precision Accuracy ----------------##
Dim firstNum, secondNum As Double
'## Variables FirstNum & SecondNum are Declared as Numeric -----##
'## Error_handler will Trigger if Non-Numeric Values are Entered ---##
On Error GoTo error_handler
'## If Input from TxtNum1.Text or TxtNum2.Text ------------------##
'## Contains Non-Numeric Value Then ---------------------------##
'## [On Error Goto] error_handler will be triggered ----------------##
firstNum = TxtNum1.Text
secondNum = TxtNum2.Text
Lbl_Answer.Text = firstNum / secondNum
'## To prevent error handling even the inputs are valid---- ##
Exit Sub
'## Error Handler Routine ##
error_handler:
'## Error Detected in Equation through Non-Numeric Input --------##
Lbl_Answer.Text = "Error"
'## Declaring Lbl_ErrMsg.Text as Visible --------------------------##
Lbl_ErrMsg.Visible = True
Lbl_ErrMsg.Text = " One or both of the entries is/are non-numeric! Try again!"
End Sub
Private Sub InitialClear_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'## Clear Variables at Initial Startup Procedure--------------------- ##
Lbl_ErrMsg.Text = ""
Lbl_Answer.Text = ""
End Sub
End Class