NAMING CONVENTIONS

Many development teams adopt naming conventions to make their code more consistent and easier to read. Different groups have developed their own conventions, and you cannot really say that one of them is best. It doesn’t really matter which convention you adopt. What is important is that you develop some coding style that you use consistently.

One rather simple convention is to use lowercase_letters_with_underscores for variables with routine scope, MixedCaseLetters for variables with module and global scope, and ALL_CAPS for constants of any scope. For example, the following statement defines a module-scope PictureBox variable:

Private Canvas As PictureBox

Routine names are generally MixedCase.

Many developers carry these rules a bit further and add type prefix abbreviations to control names. For example, the following code declares a PictureBox variable:

Dim picCanvas As PictureBox

Some developers add scope prefixes (m for module, g for global), and some also add type prefixes to variables other than controls (such as iNumEmployees for an integer) and even to subroutine names (as in gstrGetWebmasterName for a global function that returns a string). Visual Studio’s IntelliSense will tell you a variable’s data type if you hover the mouse over it so these more complex prefixes are not as useful as they were before IntelliSense became so powerful. For that reason this type of prefix is much less common than it used to be.

No matter which convention you use, the ...

Get Visual Basic 2012 Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.