Tip 9: Trace the stack.

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 internal 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:

Public Sub Testing() ' Set up general error handler. On Error GoTo Error_General_Testing:     Const sProcSig = MODULE & " General.Testing"     Call TrTraceIn(sProcSig)          ' ========== Body Code Starts ==========     .     .     .     ' ========== Body Code Ends ==========          Call TrTraceOut(sProcSig)     Exit Sub      ' Error handler. Error_General_Testing:     .     .     . End Sub 

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.



Ltd Mandelbrot Set International Advanced Microsoft Visual Basics 6. 0
Advanced Microsoft Visual Basic (Mps)
ISBN: 1572318937
EAN: 2147483647
Year: 1997
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net