Website Design United States, Website Design California, Website Designing United States, Website Designing California

Here are 8 steps to improve the readability, debug-ability and

speed of your VB6 application.

1) Use Option Explicit (and the Require Variable Declaration setting) for ALL your modules and forms.

This requires you to explicitly declare your variables. If you don't explicitly declare your variables, then you have two problems. First, those variables become variants, instead of the variable type you want. Variants are slow and ugly to deal with. Second, debugging code can be difficult, since a mistyped variable name can create a new instance of a variable, when you intended for it to use a pre-existing variable.

2) Use the & symbol to concatenate strings, not the + symbol.

The & is faster, and leads to less confusion. + should only be used for math.

3) Use the String version of functions, instead of the Variant version.

See Step 1 about variants. Many functions have a string version and a variant version. The string version returns a string. The variant version returns a variant, which is them implicitly converted to a string, if your using the result as a string (which is about 99.999% of the time). Here are some examples of functions that have string versions. Format() should be Format$(). Left, Right, Mid, UCase, LCase, Space, String, Trim, LTrim, RTrim. There are many many others. You can find out if they have a string version, but typing in the function name, then pressing F2. This brings up the Object Browser. Look for your function. If you see a version of the function with the $, then it has a string version, and you should use that.

4) Proper indentation.

Indentation makes your code easier to read, and leads to easier debugging. There are some nice tools available for VB that will properly indent your code automatically.

5) Use a naming convention.

You should always use a naming convention. This makes reading your code easier, and that leads to easier debugging. Read this article on Naming Conventions for more information.

6) Use longhand declarations.

This is an example of a shorthand declaration: Dim pA& If you don't know that & is a long, then you don't know what type of variable that is. You should use the longhand version, like this: Dim pA as Long - This also relates to Step 5, and leads to easier debugging and readability.

7) Keep scope as tight as possible.

If you can use a private string in a module, instead of a public string. Use the private string. If you can make a string local to a routine, and return it using a function, instead of making the string module level, then make the variable local, and return it via a function. This helps with readability, debugging, and speed. The smaller the scope of a variable, the less resources used, and the faster your program executes.

8) Comment your code.

You should always put in comments explaining what a section of code does. If something is particularly complex, then comment EACH LINE, so you know what is going on. This aids in readability and debugging.

In conclusion:

The above 8 steps will greatly improve your code. This will also make you more marketable, since your code is easier to read, and this makes you more useful in a group enviroment. There are many other speed optimizations you can make, but by avoiding variants, and using the string version of functions, you can significantly speed up just about any program.













 


© 2008-2009 dotnet4all.com