Other topics about Operation Basics
Errors in VBA programs are classified into the following two types:
A syntax error is generated when Visual Basic Editor detects an invalid statement that violates the Visual Basic syntax rules. For example, misspelled keywords generate syntax errors. An error dialog box appears that indicates the error message, and highlight the invalid statement in red. To get detailed information on the error, click the HELP button in the error dialog box to display the help topic on the error. You cannot run the macro until you correct the syntax error.
The E5071C VBA environment is by default configured to automatically check for syntax errors, but you can disable the auto syntax check feature using the following steps:
On the Tools menu, click Options....
On the Editor tab, clear the Auto Syntax Check check box.
Click the OK button.
A run-time error is generated when a VBA program attempts to execute an invalid statement at run time. When a run-time error is generated, the program is stopped at the invalid statement, and an error dialog box appears. You can terminate the program by clicking the END button in the error dialog box. Also, you can click the DEBUG button in the error dialog box to identify the statement that caused the error. In this case, the statement in question is highlighted in yellow.
Some run-time errors occur under particular conditions, even though a program run without occurring the errors under normal conditions. For example, the "Target value not found" error that occurs when a program that analyzes the results using the Marker Bandwidth Search feature fail to perform bandwidth search because the marker is not in the appropriate position, the "Ecal module not in RF path" error that occurs when a program that performs calibrations using a ECal module fail to measure the calibration data because the ECal module is not appropriately connected to test ports, and so on.
The E5071C's VBA environment provides a variety of debug tools that help you identify logical errors. Detailed information on using the debug tools is covered in VBA Online Help and books on VBA.
The debug toolbar provides tool buttons that allow you to easily access various debug tools.
On the View menu, click Toolbars > Debug.
Set/clear break points (keyboard F9): Puts a break point at the cursor position or clears an existing break point.
Step-in (keyboard: F8): Runs the VBA program step by step. If the current program contains a call to another procedure, that procedure is also run step by step.
Step-over (keyboard: Shift + F8): Runs the VBA program step by step. If the current program contains a call to another procedure, that procedure is run as one line.
Step-out (keyboard: Ctrl + Shift + F8): Executes the remaining lines of the function where the execution point is currently placed.
Local window: Opens the local window that shows the current values of local variables.
Immediate window (keyboard: Ctrl + G): Opens the immediate window that evaluates entered values of variables or expressions.
Watch window: Opens the watch window that displays the current value of a specified expression.
Quick window (keyboard: Shift + F9): Displays the current value of a specified expression in a dialog box.
By placing a break point at a particular statement in a VBA program, you can automatically suspend the program when it is executed to that statement.
When you put a break point at a line, the line is highlighted in umber as shown in the following figure. To set a break point, do one of the following:
Place the cursor at the desired line of code, and click the "Set/clear break points" button on the debug toolbar.
Click anywhere in the margin indicator bar of the code window.
Setting a break point
With your VBA program suspended, you can use the following debug tool to monitor variables or properties. To do this, you must set a break point, run the VBA program, and suspend it.
When you point to the variable or expression of interest, Data Hint shows the current value as shown in the following figure.
Data Hint
To display the immediate window, click on the debug toolbar.
In the immediate window, enter a question mark (?) followed by the variable or expression whose value you want to check, and press the Enter key, as shown in the following figure. The current value appears in the line that follows.
Immediate window
To display the watch window, click the "Watch Window" button on the debug toolbar.
Watch window
On the Debug menu, click Add Watch.... to open the Add Watch dialog box.
As shown in the following figure, you can specify an expression of interest as a watch expression to always monitor its value.
Click the OK button.
Add Watch dialog box
In the code window, select a variable or expression whose value you want to watch. On the debug toolbar, click the "Quick Watch" button to open the Quick Watch dialog box. The dialog box displays the current value of your specified variable or expression.
Also, you can click the Add button in the Quick Watch dialog box to specify the current expression as a watch expression.