Page 76 - Excel for Scientists and Engineers: Numerical Methods
P. 76

CHAPTER 2    FUNDAMENTALS OF PROGRAMMING WITH VBA                     53


                    Insert a Stop statement in the VBA code.
                    Enter  a  break  expression  in  the  Add  Watch  dialog  box  (see
                     "Examining the Values of Variables" later in this chapter).























                                  Figure 2-24.  VBA code with a breakpoint.

                   When  you  run  the  macro,  the  code  will  execute  until  the  breakpoint  is
                reached, at which point execution will stop.  You can now step through the code
               one statement at a time or examine the values of selected variables, as described
                in the following sections.
                   Since you can't  "run" a Function procedure, the only way to step through a
                Function procedure is to add a breakpoint, then recalculate a formula containing
                the custom function.
                   To  remove  a  breakpoint,  click  on  the  breakpoint  indicator,  or  place  the
                cursor on the highlighted line and press the Toggle Breakpoint button, or delete a
                Stop statement.

                Examining the Values of Variables
                While in Break Mode
                   You can examine the values of selected variables while in Break Mode.  You
                get to be in Break Mode by one of the following:
                   Your procedure generated a run-time error and halted.
                   Your procedure reached a line with a breakpoint or a Stop statement
                   To  see  the  current  value  of  a  variable,  highlight  the  variable  by  double-
                clicking on it, or simply place the cursor over the variable.  The current value of
                the  variable  will  be  displayed  in  a  yellow  "InfoBox"  next  to  the  cursor,  as
                illustrated in Figure 2-25.
   71   72   73   74   75   76   77   78   79   80   81