Debugging
Syntax error– the statement is not
constructed according to Visual Basic rules. Visual Basic doesn’t
understand the statement.
Run-time error – the error will cause the
program to stop when it is running because of an error condition
outside of the program. One example is when a data file is missing,
or not where the program expects it to be.
Logic error – the program creates output
that is not accurate. This could be because the wrong variable name
is used, or because a formula is inaccurate.
Any of these errors can be caused by typing
errors.
Visual Basic makes this easy. When you type a
statement with a syntax error, the error will have a blue squiggly
underline. In the example, the word End was typed with a space between
the e and the n. After enter was pressed, the parenthesis were
added. The blue squiggly underline is VB’s way of say huh?

Set a Break Point
- In the code view, point toward the line of
code within the grey bar in the left margin. Click. A round mark
will appear in the gray bar, which marks the Break Point.

You can move the mouse to hover over each
variable or object in the code, and a pop up box will appear. The box
will display the variable or object’s name and value. Logic errors are
often found in IF statements.

Step Into
Click the Step into button in the debugging tools
to execute the next line, then stop. You can check the results of each
line of code this way.

The next line will execute and will show
highlighted in yellow in the code window.

Remove a Breakpoint
Point at the breakpoint circle mark and click
it. It will disappear.
Autos
The Autos window will open at the bottom to the
screen. Each variable or object will be listed with the current
value. As you click the Step into button, these items will change,
showing the current status of these important program elements.
This is a useful way to move through the program
and see where a value is not calculating as you expected, or planned.
The window will only display those variables
which are active. Once you proceed in the code past the point where
the variables are active, they will disappear from this window.
- Pull down the Debug menu, choose Windows, then
choose Autos.

The Autos window appears in the bottom of the
screen.

Watch Window
The watch window will display the variable
throughout the execution of the entire program. Visual Basic 6
facilitates up to 4 watch windows.
The watch window is started when a breakpoint
stops the program.
- Set a breakpoint.
- Start debugging.
- When the breakpoint is reached, and execution
stops, point at the variable you want to watch, right click and
choose Add Watch.

The Watch window will appear in the bottom left
part of the screen. The variable’s name, value and type will display.
The variable will remain in the window throughout the program’s
execution, even when it is not active.

The Immediate Window
The intermediate window allows you to set the
value of a variable while the program is running.
To open the Intermediate Window, pull down the
Debug menu, choose Windows, then Immediate.

-
Start debugging.
-
When you reach a breakpoint, type any variable
name, an equal sign, and then the value or text you want to assign
to it. If the variable type is text, you will need to enclose the
text in quote marks.
-
Press enter.
When you hover over the variable name, you will
see your new value. It will also appear in any Watch window or Autos
window. |