Stepping through a Macro
Stepping through a macro lets you execute execute as few a s one instruction at the time to see :
•The path of execution that your macro takes. This is particularly useful when your code includes if-else branches, to see which brach of the condition was executed.
•The values of the macros variables at each step.
There are 3 ways of stepping through a Macro :
•Run to the end (F9) : This is used when a macro is long and you wish to either see only its end-result for different initial conditions, or in conjunction with a breakpoint to immediately start testing at a particular line.
•Line by line (F8) : This is the usual way of testing. Each time you press F8, one line or source code is executed, and the new variable values are updated in the Watches Window. Note that you can view the compiled code while testing line-by-line. It is actually rather interesting to see the instruction pointer jump through multiple instructions in response to a move of a single source code line.
•Step into (F7) : This lets you step through the compiled code, and is destined to those who understand compiled code and even so, in cases when the normal F8 testing is too coarse. This is the most detailed method since a single source code line can often generate many compiled instructions (particularly in the case of nested functions).
To illustrate the difference between the use of F7 and F8, consider the following examples. As you step through a macro, the source code line that will be evaluated next is denoted by an arrow in the left margin of the code editor.
The compiled code line that will be executed next is also highlighted.
However, note how the selected source code line (line 11) translates into 3 separate compiled code lines (each beginning with 0011).
•Using F8 at in the situation above would execute all 3 compiled code lines before stopping and updating the values of the macro's variables in the watches window.
•Using F7 would only execute the currently selected compiled code line and would stop, letting you view the values of the macro's variables, before moving to the next line. Note that in this case using F7 would cause the selected compiled code to move by one everytime, but the selected line in the source code would remain on line 11 until all 3 instructions beginning with 0011 were executed.
You can switch testing modes between F7 and F8 as you wish (and even F9 if it was stopped by a breakpoint). For example, you could set a breakpoint in the body of the code where you wish to understand what is going on. You would press F9 to reach it, and once there you would use either F7 or F8.
Finally, note that before executing the first line of your code, Q++ will try to compile it. If your code cannot be compiled Q++ will issue a message to that effect and abort the step by step execution of your macro.