A generous use of these will help pinpoint any problems.
update: added some Tix macros to find CPU hogs (page 2)
update #2: added Class Error Macros (page 3)
- exit Method or Property
- print debug message - only show in debug mode
- set Class error flag
- set Class error message
update: added some Tix macros to find CPU hogs (page 2)
update #2: added Class Error Macros (page 3)
- exit Method or Property
- print debug message - only show in debug mode
- set Class error flag
- set Class error message
Code:
[FONT=Times New Roman]'pb 4,5 ~ 8,9[/FONT] [FONT=Times New Roman]'DebugExit.inc[/FONT] [FONT=Times New Roman]'[/FONT] [FONT=Times New Roman]'the evaluation isn't done inside parentheses (test) - PB's short circuit evaluation works as expected[/FONT] [FONT=Times New Roman]'procedure = Sub, Function, Method; whatever type of procedure macro used in[/FONT] [FONT=Times New Roman]'Function GetThis(ByVal x As Long) As Long[/FONT] [FONT=Times New Roman]' ErrExitFalse(x, Function, "x = null")[/FONT] [FONT=Times New Roman]' 'rest of code ...[/FONT] [FONT=Times New Roman]'End Function[/FONT] [FONT=Times New Roman]'[/FONT] [FONT=Times New Roman]' if x = 0 and in Debug mode; message gets printed[/FONT] [FONT=Times New Roman]' "GETTHIS: x = null"[/FONT] [FONT=Times New Roman]' if not in Debug mode - just exits the Function[/FONT] [FONT=Times New Roman]'[/FONT] [FONT=Times New Roman]'ErrExitTrue(IsNothing(MyObj), Method, "MyObj failed")[/FONT] [FONT=Times New Roman]'[/FONT] [FONT=Times New Roman]Macro ErrExitFalse(test, procedure, msg)[/FONT] [FONT=Times New Roman]'exit procedure if test = False[/FONT] [FONT=Times New Roman]' print Debug message (only prints in Debug mode)[/FONT] [FONT=Times New Roman]'[/FONT] [FONT=Times New Roman]' this avoids using parentheses: (test) = %FALSE : PB's short circuit evaluation works as expected[/FONT] [FONT=Times New Roman]'[/FONT] [FONT=Times New Roman]If test Then[/FONT] [FONT=Times New Roman]Else[/FONT] [FONT=Times New Roman] #Debug Print FuncName$ +": "+ msg[/FONT] [FONT=Times New Roman] Exit procedure[/FONT] [FONT=Times New Roman]End If[/FONT] [FONT=Times New Roman]End Macro[/FONT] [FONT=Times New Roman]Macro ErrExitTrue(test, procedure, msg)[/FONT] [FONT=Times New Roman]'exit procedure if test = True[/FONT] [FONT=Times New Roman]' print Debug message (only prints in Debug mode)[/FONT] [FONT=Times New Roman]If test Then[/FONT] [FONT=Times New Roman] #Debug Print FuncName$ +": "+ msg[/FONT] [FONT=Times New Roman] Exit procedure[/FONT] [FONT=Times New Roman]End If[/FONT] [FONT=Times New Roman]End Macro[/FONT] [FONT=Times New Roman]Macro ErrGoFalse(test, MARKER, msg)[/FONT] [FONT=Times New Roman]'GoTo MARKER: if test = False[/FONT] [FONT=Times New Roman]' print Debug message (only prints in Debug mode)[/FONT] [FONT=Times New Roman]If test Then[/FONT] [FONT=Times New Roman]Else[/FONT] [FONT=Times New Roman] #Debug Print FuncName$ +": "+ msg[/FONT] [FONT=Times New Roman] GoTo MARKER[/FONT] [FONT=Times New Roman]End If[/FONT] [FONT=Times New Roman]End Macro[/FONT] [FONT=Times New Roman]Macro ErrGoTrue(test, MARKER, msg)[/FONT] [FONT=Times New Roman]'GoTo MARKER: if test = True[/FONT] [FONT=Times New Roman]' print Debug message (only prints in Debug mode)[/FONT] [FONT=Times New Roman]If test Then[/FONT] [FONT=Times New Roman] #Debug Print FuncName$ +": "+ msg[/FONT] [FONT=Times New Roman] GoTo MARKER[/FONT] [FONT=Times New Roman]End If[/FONT] [FONT=Times New Roman]End Macro[/FONT]
Comment