Number 屬性 (Err 物件)

更新:2007 年 11 月

取得或設定用來指定錯誤的數值。讀取/寫入。

Public Property Number() As Integer

備註

從物件傳回使用者定義的錯誤時,請將您選取做為錯誤碼的數字加入至 VbObjectError 常數,以設定 Err.Number。例如,您可使用下列程式碼,將數字 1051 當做錯誤碼傳回。

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

範例

這個範例會說明 Number 屬性在錯誤處理常式中常見的用法。這個範例也會使用 Description 屬性,以便提供錯誤說明。

' 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
out:
  MsgBox(Err.Number)
  MsgBox(Err.Description)
  ' Check for division by zero error.
  If Err.Number = 11 Then
      y = y + 1
  End If
  Resume Next
End Sub

需求

命名空間 (Namespace)︰Microsoft.VisualBasic

**模組︰**ErrObject

組件:Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

請參閱

參考

Err 物件 (Visual Basic)

Description 屬性 (Err 物件)

ErrorToString 函式

HelpContext 屬性 (Err 物件)

HelpFile 屬性 (Err 物件)

LastDllError 屬性 (Err 物件)

Source 屬性 (Err 物件)