Difference between revisions of "Debugging"

From HashVB
Jump to: navigation, search
(Preliminary debugging information)
 
(Link to IRBMEs PDF)
Line 30: Line 30:
  
 
If you have tried these and still can't see what is going wrong, feel free to ask in #VB on [http://www.undernet.org Undernet] at [irc://irc.undernet.org/vb irc.undernet.org].
 
If you have tried these and still can't see what is going wrong, feel free to ask in #VB on [http://www.undernet.org Undernet] at [irc://irc.undernet.org/vb irc.undernet.org].
 +
 +
==See also==
 +
[http://evil-geni.us/~irbme/Public/programming/debugging.pdf Debugging Visual Basic 6 Code (PDF)]

Revision as of 12:17, 9 September 2005

So, something is not working as it should do. There are a number things you can use to try and track the problem down.

Please note that you should use Option Explicit in all your VB programs. This will cause you to declare all variables but will eliminate numerous problems with spelling mistakes in variable names and type conversion issues.

Breakpoints

Breakpoints will pause the execution of the program where that point is encountered. This allows you to use the Info tips and the Watch/Locals window to monitor variables at certain points in the program and step through the code.

You can toggle a breakpoint on any executable line by pressing F9 or clicking adjacent to the line in the grey bar on the left. If you need to immediately pause a running program, you can use CTRL+Break or press the pause button in the VB IDE. You can also use the Stop statement which will break a running program but if left in a compiled program, it will be a fatal error and terminate the program.

Single stepping

Single stepping is a feature of the Visual basic environment that allows you to step through the code a line at a time using the F8 key.

Info tips

While in break mode, VB allows you to hover over a variable or expression to see its value. This will also call a function and show the result.

Watch/Locals window

The Watch and Locals windows allow you to see the state of various variables and expressions while stepping through the code or in break mode. It also allows you to add a watch to break when a variable changes value or becomes true.

Immediate window

The immediate window will allow you to view the output of the Debug.Print statement as well as running lines of code typed in.

If you have tried these and still can't see what is going wrong, feel free to ask in #VB on Undernet at irc.undernet.org.

See also

Debugging Visual Basic 6 Code (PDF)