As you saw in the log file in Listing 1-3, we dump the VBA call stack when we hit an unexpected error because it can be useful for working out later what went wrong and why. We build an inter 15215k1017p nal representation of VBA's stack (because VBA's stack is not actually available-shame), using two fundamental routines: TrTraceIn and TrTraceOut. Here they are in a typical routine:
These routines are inserted by hand or by using the same internal tool I mentioned earlier in Tip 2 that adds line numbers to code. Notice that sProcSig is being passed into these routines so that the stack can be built containing the name of the module and the routine.
The stack frame object we use internally (not shown here) uses a Visual Basic collection with a class wrapper for its implementation. The class name we use is CStackFrame. As a prefix, C means class, and its single instance is named oStackFrame. We drop the o prefix if we're replacing a standard class such as Err or App.
|