Why is it when I use Err.Raise 65536
the Err.Number
will actually have the value of 5 and not 65536?
According to Raise
definition: Sub Raise(Number As Long, [Source], [Description], [HelpFile], [HelpContext])
. The passing parameter is Long
and Err.Number
is also Long
.
So why can't I use values greater then 65535?
Private Sub Command1_Click()
Dim a As Long
On Error GoTo ErrCatch
For a = 0 To 99999
Err.Raise a
DoEvents
Next a
Exit Sub
ErrCatch:
' this is where Err.Number is evaluated
Resume Next
End Sub`
From the MSDN documentation:
Number
Required. Long integer that identifies the nature of the error. Visual Basic errors are in the range 0–65535; the range 0–512 is reserved for system errors; the range 513–65535 is available for user-defined errors. When setting the Number property to your own error code in a class module, you add your error code number to the vbObjectError constant. For example, to generate the error number 513, assign vbObjectError + 513 to the Number property.
So even though you can submit a value larger than 65535, anything larger than 65535 will become Error 5.