This example uses the Err object's Clear method to reset the numeric properties of the Err object to zero and its string properties to zero-length strings. If Clear were omitted from the following code, the error message dialog box would be displayed on every iteration of the loop (after an error occurs) whether or not a successive calculation generated an error. You can single-step through the code to see the effect.
Dim Result(10) As Integer ' Declare array whose elements
' will overflow easily.
Dim indx
On Error Resume Next ' Defer error trapping.
Do Until indx = 10
' Generate an occasional error or store result if no error.
Result(indx) = Rnd * indx * 20000
If Err.Number <> 0 Then
MsgBox Err, , "Error Generated: ", Err.HelpFile, Err.HelpContext
Err.Clear ' Clear Err object properties.
End If
indx = indx + 1
Loop