Valhalla Legends Forums Archive | Battle.net Bot Development | $t0rm's quick-and-easy guide to debugging in VB

AuthorMessageTime
St0rm.iD
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 ;)
March 21, 2003, 8:17 PM
Camel
right, dont mention camel for suggesting the idea :'(
March 21, 2003, 9:13 PM
St0rm.iD
Camel gave me the idea.
March 21, 2003, 10:20 PM
Camel
8)
March 21, 2003, 10:50 PM
MesiaH
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...
March 22, 2003, 9:54 PM

Search