Debugging

Debugging

Visual Basic provides many tools to help analyze how your code operates. These debugging tools are particularly useful in locating the source of errors, or bugs. You can also use them to help you learn how code written by other people works. When you write your code, you will never be able to create code that works first time round perfectly. Or if you do, if you change another section of code, this may well affect code you have already written which then does not work. There are generally three types of errors:

Run Time Errors

These occur while your application is running, when Visual Basic finds a statement that is impossible to carry out, such as multiplying the contents of TextBox1 by 10 when textbox1 contains 'Hello'. If this error occurs when running Visual Basic, a dialog is displayed like the one below. You are given the error number along with its message. You have the option to End the current program, Debug the program which pauses the code, or to get help on that error


Visual Basic Error Dialog Box

If however an error occurs once your application has been made into an exe, the error number and message are given. But once the OK button has been pressed, the program closes.

Language Errors

These result from incorrectly structured code. For example, having an Do statement without a corresponding Loop statement, or an opening quote for a string, but no closing one. These sorts of errors are picked out, either the moment you leave the line in the case of the missing quotes, or just before the code executes in the case of the Do...Loop example.

Logic Errors

These errors occur when the code you have written does not run the way you expected it. No error message is given as the code is using the correct syntax, and is not performing invalid operations, however it is not giving the expected result. This is by far the hardest error to track down. Only by going through your code very methodically and analysing your results will you be able to find the cause (or by very good luck, but don't rely on it!)

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The greatest performance improvement of all is when a system goes from not-working to working.” - John Ousterhout