Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Troubleshoot Code VB6


Mohenjo Daro
 Share

Recommended Posts

It's occurred to me that most people don't know to troubleshoot issues they have in VB6 while coding, so here's a quick guide to try and teach you how.

**NOTE: Before changing your project's code (even if it's from a tutorial) ALWAYS make a copy of your client and server source code, date it, and add a description like "12-07-2016 backup before guilds". This will make you life 1000x easier if you add the code in wrong. BACK UP YOUR CODE. Just remember to delete the old backups when you finish changing the code and have it stable.**

NOTE: Disregard the above note if you use a source control (source controls manage your changes for you so you can revert back to them at a later date, examples are GitHub and Mercurial).
If requested I can make a tutorial on how to use Mercurial to manage your source (it's what I use for work and ER).

* * *

* * *

-**Break Points:**

**Adding:**
Break points are the most important troubleshooting tool, without them you have a very hard time with figuring out the issue (yes, you can use msgboxes, and for awhile I did and most coders have, but please don't. They are nasty and easily forgotten about). To add a break point to your code, left click the side of the VB6 client where the red dot is
![](https://puu.sh/wHEzO/00699f1e9e.png)

You have successfully added a break point

* * *

**Using:**
While debugging, if the line of code is used, the debugger will stop and the line will turn yellow. You can hover over variables on that line (and other lines) to see the current variable value, like so:
![](https://puu.sh/wHEYy/969732ce3f.png)

This very handy when trying to make sure you used the right value when setting a variable, or when trying to figure out why there is an overflow error (make sure you didn't need to - 1 from the value ;) )

* * *

**What it means:**
Making it to a break point means that the code until that point works, if you don't make it to your break point then the issues lies further back in the code. This is very helpful when dealing with calls or loops.

* * *

* * *

**Break Points Everywhere???:**
Please, for the love of sanity, don't add breakpoints everywhere. It's not fun to look at, and it's not fun to get rid of. "But I need them to find the issues!" You don't though, because there is a really cool secret you can use!

F8

Once you hit your break point, press F8 and you will go to the next line of code, press it again and you will go to the next one again. You will go 1 line at a time debugging so you can see the variable values in real time. "But it keeps calling all these statements!" Yes, it will do that, and here's another secret…

Shift + F8

This will let you skip over call subs and functions so you stay in the sub and don't get sent everywhere in your code.

F8 will let you keep your break point count to a minimum.

* * *

**Finding the Bug:**
Now that you have 2 new tools in your arsenal, break points and F8, we can start learning some ways to find a bug.

**What'd You Do?**
Coding or playing, what you did is very important to finding a bug: did you open your inventory, did you hover over an item, did you try using a weapon, etc.? If you opened an inventory or hovered over an item, there's a high change the bug is a graphics related issue; using a weapon is a combat related bug; loading the client is a database related bug; and so on.

Knowing this allows you to know a relative area to put a break point. If you get to that break point, then you can put on a little further down and then press F5 to quickly see if you can get to that break point as well. Getting to that break point means to add a new break point and do it again until you don't; not getting to the break point means the problem is somewhere between and you can keep narrowing it down using this method until you get to a small enough region to use F8.

* * *

**Fixing the Bug:**
Ok, so you found that the error is on
![](https://puu.sh/wHEYy/969732ce3f.png)

You look and find out that a folder is missing. You now have to make a sub/line to check for that folder, if it doesn't exist then that line will create it.

An error while in a loop usually is caused by the loop going higher than the value you're working with:
```
For i = 1 To Stats.Stat_Count
    Player(MyIndex).Stat(i)
Next
```Will give you an error because the stat count is 6 but there are 5 stats. You forgot the " - 1".

* * *

* * *

**I'm Done:**
Ok, so you've fixed the bug, but it was a big system and you added a lot of break points. All you have to do is save your project and close it. The break points aren't saved so when you repoen it, they will no longer be there.

* * *

* * *

I may have forgotten a few tips and tricks, so feel free to leave any I forgot and I'll add them to the tutorial.

P.S. Thanks for uploading the images, Benjo, they were very handy to stea- *erhm* use :)
Link to comment
Share on other sites

Also,

Would like to add if you do use a lot of break points to follow a huge system, say instancing, and you used way over 40 break points to follow something. You should save and close and all break points will be removed. Now, before you go and save a broken source remember: Always make a back up before edits. Most mid to high programmers back up before large edits but if you're just starting out I suggest backing up the complete client + server folders and naming them correctly like "12 07 2017 Working before Instances" or "12 07 2014 backup before guilds".
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...