• Welcome to Valhalla Legends Archive.
 

$t0rm's quick-and-easy guide to debugging in VB

Started by Banana fanna fo fanna, March 21, 2003, 02:17 PM

Previous topic - Next topic

Banana fanna fo fanna

I'm just writing this off of the top of my head because I see the same posts time and time again from people who can't debug their own programs.

I'll assume you're working in VB5 or VB6, and your bot works (i.e. connects to battle.net and you can sort of chat with it). I'll write examples for CSB.

Let's say that you can't figure out why the users aren't being removed in your channel list. I dunno, it's a bug I picked out of thin air. Your winsock control will receive the userleave notificiation in the CSBControlNameHere_UserLeaves() procedure. Place a breakpoint on that line. Put your cursor (text cursor, not mouse) on the line, and press F9. It turns red.

What's a breakpoint? Well, when you run your program, VB will stop before the breakpointed line is executed. This can be very helpful, as we will soon see.

Run your bot. When a user leaves the channel, VB's code editor will pop up and you'll see the line you breakpointed is highlighted. Press F8 to move to the next line. Continue pressing F8 until you see the bug appear (the user not being removed). If something doesn't seem right in the way VB executed your code, go back and examine your code.

First, give it a once-over with your eyes. Does everything look right? If so, repeat the above process, except when you enter the block of code, after each line examine the variables. Well how do you do that? Hold the mouse over the variable you want to look at, for example, listIndex. A tooltip will show up with the value of the variable in it. Try to figure out in your head what the value of the variable should be and what it really is in the program. If it's wrong, you may have found your bug. Go back, and look at anything that manipulates the variable, and see if it is correct. Repeat until the bug is corrected.

This is just an introduction, but I'll cover one last thing: step over. Pressing F8 is known as 'stepping into' a statement. If the statement calls a procedure (sub or function), you will enter that procedure. If you don't want to enter it, you can press Shift+F8 to skip over it. This is useful when you know one of your procedures is correct and it doesn't require debugging.

This is an introduction, consult the VB documentation/Google for advanced stuff like watches.

Spht you can add this to botdev if you think it's useful ;)

Camel

#1
right, dont mention camel for suggesting the idea :'(

Banana fanna fo fanna

#2
Camel gave me the idea.

Camel

#3
8)

Mesiah / haiseM

It could be a good idea to add it to the botdev site, but its all common sense, and thats something everybody should know how to do before even entering a highly detailed programming field, so putting it on his website would not really contribute to battle.net bots...
]HighBrow Innovations
Coming soon...

AIM Online Status: