Well, actually there
is a way of making things a bit easier for you. I've been playing around with the VB IDE object model a while ago and I found it's quite easy to process VB projects. You can then have the kind of error checking you want automated. It's a bit of work, but once done it saves you a lot of trouble in the process of developing future projects in VB.
To give you a general idea of what I'm talking about, here's the procedure that actually inserts error handlers. Please forgive me, it's rather sloppy (was just playing around for testing and never got to cleaning it up) but it
does work:
Private Function DoProcessMember(ByVal mbr As VBIDE.Member, ByVal cod As VBIDE.CodeModule, ByVal strFile As String, ByVal strName As String) As Boolean
'Processes the specified piece of code.
'
'mbr [IN]: The member to be processed (can be either a method or a property procedure).
'cod [IN]: The code module that contains this piece of code.
'strFile [IN]: The file name (excluding the path) of the code module.
'strName [IN]: The name of the module being processed.
'
'Returns True if succesfull, returns False if not.
Dim blnCase As Boolean
Dim intLoc As Long, n As Integer, intFirst As Integer, intLast As Integer
Dim strMsg As String, strLine As String
DoProcessMember = False 'Default to False.
On Error GoTo ErrHandler
If cod.Find("Declare Function " & mbr.Name, intLoc, 1, -1, -1, True, True) Then DoProcessMember = True: Exit Function
If cod.Find("Declare Sub " & mbr.Name, intLoc, 1, -1, -1, True, True) Then DoProcessMember = True: Exit Function
If mbr.Type = vbext_mt_Property Then 'Property procedures have two locations (Get and Let/Set), these have to processed both.
intLoc = 1
If cod.Find("Property Get " & mbr.Name, intLoc, 1, -1, -1, True, True) Then GoSub ProcessCode
intLoc = 1
If cod.Find("Property Let " & mbr.Name, intLoc, 1, 1, -1, -1, True, True) Then GoSub ProcessCode
intLoc = 1
If cod.Find("Property Set " & mbr.Name, intLoc, 1, 1, -1, -1, True, True) Then GoSub ProcessCode
Else 'Methods have but one.
intLoc = mbr.CodeLocation
GoSub ProcessCode
End If
DoProcessMember = True 'All went well.
Exit Function
ProcessCode:
intLoc = intLoc + 1: intFirst = intLoc 'The location of the first line after the procedure declaration.
cod.InsertLines intLoc, Chr$(9) & "On Error GoTo SysErr" & mbr.Name 'Insert a reference to the standard error handler of this procedure here.
If frmError.chkCall.Value = 1 Then cod.InsertLines intLoc, Chr$(9) & "UpdateCallStack " & Chr$(34) & strName & "." & mbr.Name & Chr$(34)
If mbr.Type = vbext_mt_Property Then 'It's a property procedure.
cod.Find "End Property", intLoc, 1, -1, -1, True, True
strLine = "Exit Property"
AfterError:
Else
intLoc = 1
If cod.Find("Function " & mbr.Name, intLoc, 1, -1, -1, True, True) Then 'It's a function, and we have the location of the function declaration now too.
cod.Find "End Function", intLoc, 1, -1, -1, True, True 'Find the end of the function.
strLine = "Exit Function"
Else 'It's a sub
cod.Find "Sub " & mbr.Name, intLoc, 1, -1, -1, True, True 'Find the location of the sub declaration.
cod.Find "End Sub", intLoc, 1, -1, -1, True, True 'Now find the end of the sub.
strLine = "Exit Sub"
End If
End If
intLast = intLoc + 3 'This is where the call to the error handler will be placed.
cod.InsertLines intLoc, Chr$(9) & "GlobalSysErrorHandler " & Chr$(34) & strFile & Chr$(34) & ", " & Chr$(34) & mbr.Name & Chr$(34) & ", Erl, Err.Number, Err.Description, " & Chr$(34) & gstrVersion & Chr$(34) & ", " & Chr$(34) & Trim$(frmError.txtLog.Text) & Chr$(34) 'The call to the global error handler.
cod.InsertLines intLoc, "SysErr" & mbr.Name & ":" 'The label of the local error handler.
cod.InsertLines intLoc, Chr$(9) & strLine 'Exit sub/fuction/property must be inserted before the local error handler !
blnCase = False
For n = intFirst To intLast - 1 'Now process each line in the member.
If Not blnCase Then 'The previous line was a 'Select Case' statement, this means that the next line is not allowed to have a label (or line number).
If DoCheckLine(cod.Lines(n, 1), blnCase) Then 'Check if the line needs processing.
glngLineNr = glngLineNr + 1 'Add a line number and replace any 'on error goto 0's'
cod.ReplaceLine n, Trim$(glngLineNr) & Space$(6 - Len(Trim$(glngLineNr))) & Chr$(9) & Replace(cod.Lines(n, 1), "On Error GoTo 0", "On Error GoTo SysErr" & mbr.Name)
End If
Else
blnCase = False
End If
Next n
Return
ErrHandler:
If Err.Number = 35 Then Resume AfterError
strMsg = "An error occured while processing the project files:" & Chr$(13)
strMsg = strMsg & Err.Description & " (" & Trim$(Err.Number) & "

."
MsgBox strMsg, vbCritical, "Automatic Error Handler:"
End Function
Greetings,
Rick