Mega Code Archive

 
Categories / VisualBasic Script / Language Basics
 

Error handling by checking the Error code

Public Sub ErrorHandling()         On Error GoTo ErrorHandling_Err         Dim dblResult As Double         dblResult = 10 / InputBox("Enter a number:")         MsgBox "The result is " & dblResult ErrorHandling_Exit:         Exit Sub ErrorHandling_Err:         Select Case Err.Number         Case 13         ' Type mismatch - empty entry            Resume         Case 11         ' Division by 0            dblResult = 0            Resume Next         Case Else            MsgBox "Oops: " & Err.Description & " - " & Err.Number            Resume ErrorHandling_Exit         End Select      End Sub