Mega Code Archive

 
Categories / VisualBasic Script / Language Basics
 

How to handle error caused by value from InputBox

Public Sub ErrorHandling()     On Error GoTo ErrorHandling_Err     Dim dblResult      As Double    ' holds the result of the division     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