Number Property (Err Object)

Gets or sets a numeric value that specifies an error. Read/write.

Public Property Number() As Integer


When returning a user-defined error from an object, set Err.Number by adding the number you selected as an error code to the VbObjectError constant. For example, you use the following code to return the number 1051 as an error code:

Err.Raise(Number:=vbObjectError + 1051, Source:="SomeClass")


This example illustrates a typical use of the Number property in an error-handling routine. The Description property is also used in the example in order to provide a description of the error.

    ' Typical use of Number property. 
Sub test()
  On Error GoTo out

  Dim x, y As Integer
  x = 1 / y   ' Create division by zero error.
  Exit Sub
  ' Check for division by zero error. 
  If Err.Number = 11 Then
      y = y + 1
  End If 
  Resume Next 
End Sub


Namespace: Microsoft.VisualBasic


Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

See Also


Err Object (Visual Basic)

Description Property (Err Object)

ErrorToString Function

HelpContext Property (Err Object)

HelpFile Property (Err Object)

LastDllError Property (Err Object)

Source Property (Err Object)