|
Visual Basic (VB and VBA) |
|
Copyright 1999-2001 Christopher Greaves. All rights reserved. Home Page and email to [email protected] |
| If in doubt, record a macro and inspect the entrails! |
Please read the DISCLAIMER.
Here is an INDEX to all the procedures.
You will probably need one copy of my GLOBAL DECLARATIONS.
Public Function ERL(ByVal strCode As String, ByVal intStatusCode As Integer, ByVal strMsg As String)
' 2001/03/10
'The properties of the Err object are set by the generator of an error—Visual Basic, an object, or the Visual Basic programmer.
'The default property of the Err object is Number. Because the default property can be represented by the object name Err, earlier code written using the Err function or Err statement doesn't have to be modified.
'When a run-time error occurs, the properties of the Err object are filled with information that uniquely identifies the error and information that can be used to handle it. To generate a run-time error in your code, use the Raise method.
'
'The Err object's properties are reset to zero or zero-length strings ("") after any form of the Resume or On Error statement and after an Exit Sub, Exit Function, or Exit Property statement within an error-handling routine. The Clear method can be used to explicitly reset Err.
'Use the Raise method, rather than the Error statement, to generate run-time errors for a class module. Using the Raise method in other code depends on the richness of the information you want to return. In code that uses Error statements instead of the Raise method to generate errors, the properties of the Err object are assigned the following default values when Error is executed:
' A generic error-handler. www.globalserve.com~cgreaves
' It makes use of two INI file routines GP (Get Parameter) and PP (Put Parameter)
' It receives an error-code (identifier), a status-value, and a text string.
' It will dump the stuff variously to the status bar, an ascii log file, and a UI message.
' It updates an error-count that can be sampled elsewhere, (if too high, stop the project).
' If the error-code is a digit-string, we will search the INI file for that code and use the returned string, if any.
' Otherwise we will use the string literally as an error message.
' We ALWAYS print the message to the status bar.
' If the error is fatal, we pop up a UI message box, and then STOP processing.
' If we can write to a standard log file, we do so; Otherwise we pop up a UI message box.
' If the ini file tells us that the run is not unattended, we pop up a UI message box.
' We update a count for the appropriate status-value in the ini file.
' Example 1: Call ERL (341, intcErrorInform, strPStyle) ' Informative, a style has been created with this name
' Example 2: Call ERL ("Exceeded maximum file size of " & intMaxDocSize, intcErrorWarn, strDocname)
' Example 3: Call ERL (231, intcErrorSevere, strDocname)
' Example 4: Call ERL (010, intcErrorFatal, "I could not write to the standard log file")
' If the ini file holds an entry for Err341, that entry may well read "A style has been created with this name."
' If the ini file holds no entry for Err231, the string "231" will be displayed.
' After displaying a UI message box for error 010, the application will stop dead.
' The following constants are used as identifiers in messages written to the log file by ERL.
' Contingency - print to status bar
Call strStatusBar(strCode & " " & intStatusCode & " " & strMsg)
' See if we can translate the error code to a full string
strCodeTrans = strGPA("Err" & strCode, "")
If strCodeTrans = "" Then
strCodeTrans = strCode
Else
End If
' If it is a fatal error, pop a UI message box and stop dead
If intStatusCode = intcErrorFatal Then
Call UIMsg(strCodeTrans, strMsg)
End
End If
' If it is a severe error, pop a UI message box and continue
If intStatusCode = intcErrorSevere Then
Call UIMsg(strCodeTrans, strMsg)
End If
' Attempt to write to the standard log file
strStandardLog = MacroContainer.Path & Application.PathSeparator & strGPA("StandardLogFile", strcApplication & ".log")
If strStandardLog = "" Then
Call UIMsg("Error Handler", "I could not find the name for the standard log file")
Call UIMsg(strCodeTrans, strMsg)
Else
'' Dim intFile As Integer
'' intFile = FreeFile
'' Open strStandardLog For Append As #intFile
'' Print #intFile, Format(Now(), "yyyymmdd"), ";", Format(Now(), "hhmmss"); ";", intStatusCode; ";", strCodeTrans; ";", strMsg
'' Close #intFile
Call LogFile(strStandardLog, ";" & intStatusCode & ";" & strCodeTrans & ";" & strMsg)
End If
' Unless the run is unattended, pop up a UI message box
If UCase(strGPA("Unattended", "Y")) = UCase("y") Then
Else
Call UIMsg(strCodeTrans, strMsg)
End If
' Now update the appropriate error count
Call strPPA("errStatus" & Trim(str(intStatusCode)), 1 + strGPA("errStatus" & Trim(str(intStatusCode)), "0"))
'Sub TESTerl()
' Call ERL("0001", intcErrorInform, "here is an informative message")
'End Sub
End Function
| We all knew nothing when we started … |
|
Home Page and Contact Information Send email to [email protected]. This page was last updated Thursday, November 15, 2001 |