Did you have any error handling specified (like in examples below)?
Post #2 at
https://www.vbforums.com/showthread....what-is-it-for
has good writeup. Old but still valid as far as I know
It seems the intent by MS was to not let things get confusing
Because Microsoft has reserved the error numbers from 1 to 2147221504 for their use and the reason why you add 2147221504=vbObjectError to what ever error number you want to raise is because things don't get confusing. Lets say you have X number of error traps within your code and you have numbered them from 1 to X without the addition of the vbObjectError constant. Then you die for some reason or are no longer working at the place you designed this code and your customer recieves error number 11 with your description but when your customer looks this error number up on MS's web site it will come back as a division by zero error.
Option Explicit 'https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/number-property-visual-basic-for-applications Sub ForceError() Dim x As Long, y As Long Dim o As clsDivide Set o = New clsDivide x = Application.InputBox("Enter X as numerator") y = Application.InputBox("Enter Y as denominator") On Error GoTo ErrHandler MsgBox o.DivideXY(x, y) On Error GoTo 0 Exit Sub ErrHandler: ' My error If (Err.Number - vbObjectError) = 515 Then MsgBox (Err.Number - vbObjectError) & " -- " & Err.Description, vbCritical, Err.Source 'another error Else MsgBox Err.Number & " -- " & Err.Description, vbCritical, Err.Source End If End Sub Sub ForceError1() Dim x As Long, y As Long x = Application.InputBox("Enter X as numerator") y = Application.InputBox("Enter Y as denominator") On Error GoTo ErrHandler If y = 0 Then Err.Raise 515, "Force Error 1", "Can't divide by zero" On Error GoTo 0 Exit Sub ErrHandler: MsgBox (Err.Number) & " -- " & Err.Description, vbCritical, Err.Source End Sub
Class clsDivideXY
My thoughts, and you can experiment with the attachment, but I don't think it really makes a lot of differenceOption Explicit Private x As Long, y As Long Function DivideXY(x As Long, y As Long) As Long If y = 0 Then Err.Raise vbObjectError + 515, "DivideXY", "Can't divide by zero" DivideXY = x / y End Function





Reply With Quote
