Debugging
- F9: Set the program breakpoint, and click the same effect on the Left bar of the Code. Re-press F9 to cancel the breakpoint.
- F8: One-Step tracking. When a sub-function is called, it will be tracked inside the sub-function.
- Shift + F8: single-step tracking, but not inside the sub-function
- CTRL + Shift + F8: jump out of the function being tracked and return the previous function directly.
- F5: run the program until an error occurs, the program ends, or the program breakpoint occurs.
- CTRL + F8: run the program until an error occurs, the program ends, the program breakpoint, or the row where the current cursor is located.
- Debug. Print var: The VaR value is displayed in the current window.
- Debug. Assert var: The program stops automatically when Var = false
In the debugging process, you can view the values of each variable in the following ways. When the variables and expectations are different, you can find the cause of the program error and modify the values accordingly:
- Immediate window (shortcut: Ctrl + G): In this window, the result value of debut. Print is displayed, and the code is calculated and run at any time. Add "?" before the code, The running result is displayed in the displayed window.
- Monitoring window: You can add variables and expressions to the monitoring window to view the values of variables and expressions in real time. You can drag variables and expressions in the code window to the knowledge window.
- Local window: You can view the current local variable and global variable values in the local window.
- Edit window: hover the mouse over the variable in the edit window to display the value of the variable.
Debug:
1. Execute the tool-> options-> Editor-> check "auto display data prompt"
When you hover the mouse over a variable or expression, a prompt window is displayed, showing its name and value.
2. Check the values of some expressions in the monitoring window by dragging the black mouse to select the expression, and then executing debugging-add monitoring. The "add monitoring" dialog box appears.
3. Select the expression ---- SHIFT + F9 ---- In the code window. The "quick monitor" dialog box appears, showing the context, expression, and value of the expression.
4. Press Ctrl + G to display the "window now ". It has four main functions:
(1). Print Information
In the window, enter Debug. Print expression 1; expression 2 ...... to display the values of each expression!
2. You can assign values to variables or attributes!
Example: form1.backcolor = 255
Maxrows = 50
3. You can test the process.
In this window, you can directly enter the process name and actual parameters to call the process.
For example:
Mysub 2 * I
4. Check the error number.
For example, enter
Error 11
When you press the Enter key, error 11 is displayed in this window. I often use this method to check the error number!
Add the following statement to the process:
Debug. Assert <condition>
You can also suspend the program
VBA entry-level debugging (2)