Issue #3
April 7th, 2001

A quick note: This article is intended for beginners or people who just want something interesting to read. =) It probably won't be of much use to an experienced programmer. 

So what is debugging? It is simply put, the process of getting rid of the different kinds of errors in your program. This, can be either a big pain, or if you're like me, a huge joy! Debugging is a big part of programming and you'd better develop some methods and things to watch for or else! Here are the different types of errors:

Syntax Errors: these are the errors that come up because you've spelt something wrong or used improper BASIC syntax. Say you spelled the PRINT command as PRUNT. QBasic would say "Syntax Error" when you tried to run the program.

Runtime Error: These errors show up during your programs execution. For example if you add two numbers into a regular integer variable and the result is larger than 32767 then you'll get an "Overflow" error.

Logic Error: these are the nasty errors. The don't halt program execution but they produce bad program results. Anyone who has made an RPG engine has most likely had one of these. I know when I was working on my scrolling, first try got the scrolling going the wrong way. It worked but the results were unsatisfactory.

Those are the types of errors. Now you're probably asking "How do I get rid of these?" Syntax errors are easy to get rid of. All you do is fix the statement so its in the right syntax. Runtime and Logic errors are harder to get rid of. Runtime errors at least you know when it happens, right where it is, so you can fix them. The only catch here is if the error is inside a DO-LOOP then QBasic will say the problem is with the do loop. In this case you have to look inside the loop or if possible comment out the DO-LOOP statement and leave the loops body intact then try running it. QBasic should stop at the actual error.. The above will also happen with IF-ELSE statements. So you need to check these very carefully! Execute the code in your head that helps me out a lot.

Logic errors are just plain annoying. These, like I said they don't stop execution, but produce unwanted results. The only thing I can say here is that you must find the code which is doing something wrong and study it, execute it in your head, and then hopefully you'll figure it out! You should also know what kind of things a variable should have in it. Also make sure you have spelt your variables right. That may sound stupid but since QBasic doesn't require that you declare your variables (excluding arrays) you could spell a variable named

loopCounter

as

loopConter

That would be enough to get the wrong values into the right places. I've done this many times. And usually it's the very last thing I look for. Sometimes I get so pissed off that I recode the whole thing! Don't let this happen too you.

Now then we can go on to something else. In QBasic there is a very handy menu at the top of the screen called "Debug". It has all sorts of tools for helping you debug. Go ahead and check it out! There are commands near the top that deal with watches. What are those? They "watch" variables and their current values. Type this program into QBasic:

FOR i=1 TO 15
 PRINT "Hello again!"
NEXT i

Now go to the Add watch command and type this in: "i = 6". Now a blue bar appears and has that expression. Run the program now. You will see that there is a 0 beside it on the blue bar! That means the expression turned true in your program. There would be a "-1" if it didn't turn true. The "Instant Watch" command lets you see the value of a variable throughout the entire program. To see it use Ctrl+Break during program execution or use Trace On. Watchpoint is the same as as Add Watch but if the expression turns true the program execution stops.

Now the last few commands deal with breakpoints. What is a breakpoint you ask? It's where program execution stops if an error occurs or if you press Ctrl+Break. Toggle Breakpoint will highlight the line where execution stopped. Clear breakpoint will get rid of the highlight. These can be a good thing because they let you see the values of variables at any given line. All you have to do it use the Immediate Windows as described below.

I'm sure you've all noticed the Immediate Window on the bottom of the QBasic editing screen. This not only lets you execute one line statements, but if your program execution is interrupted because of and error or a Ctrl+Break keystroke you can use the PRINT command to display your program variables values. This has helped me a lot. Of course if you use watches then you don't need it for that.

Alright, thats it for my debugging article! I hope I helped you out with your debugging techniques. I also hope a lot of you know what the Debug menu does now. I know when I first started using QB I had no clue what that menu was for because I didn't know how to use it. But now you do. (and so do I =) ).

This article was written by: Fling-master - http://www.qbrpgs.com

All site content is © Copyright 2001, HyperRealistic Games. This excludes content submitted by other people.