VB Conventions

Why coding conventions?

The main reason for using a consistent set of coding conventions is to standardize the structure and coding style of an application so that you and others can easily read and understand the code.

Good coding conventions result in precise, readable, and unambiguous source code that is consistent with other language conventions and as intuitive as possible.

Minimal Coding Conventions

A general-purpose set of coding conventions should define the minimal requirements necessary to accomplish the purposes discussed above, leaving the programmer free to create the program’s logic and functional flow.

The object is to make the program easy to read and understand without cramping the programmer’s natural creativity with excessive constraints and arbitrary restrictions.

To this end, the conventions suggested in this appendix are brief and suggestive. They do not list every possible object or control, nor do they specify every type of informational comment that could be valuable. Depending on your project and your organization’s specific needs, you may wish to extend these guidelines to include additional elements, such as:

  • Conventions for specific objects and components developed in-house or purchased from third-party vendors.

  • Variables that describe your organization’s business activities or facilities.

  • Any other elements that your project or enterprise considers important for clarity and readability.

For more information   For information about restrictions on naming procedures, variables, and constants, see "Code Basics" in "Programming Fundamentals."

 

When you first create an object (form or control), Visual Basic sets its Name property to a default value. For example, all command buttons have their Name property initially set to Commandn, where n is 1, 2, 3, and so on. Visual Basic names the first command button drawn on a form Command1, the second Command2, and the third Command3.

You may choose to keep the default name; however, when you have several controls of the same type, it makes sense to change their Name properties to something more descriptive. Because it may be difficult to distinguish the Command1 button on MyForm from the Command1 button on YourForm, a naming convention can help. This is especially true when an application consists of several form, standard, and class modules.

You can use a prefix to describe the class, followed by a descriptive name for the control. Using this naming convention makes the code more self-descriptive and alphabetically groups similar objects in the Object list box. For example, you might name a Check Box control like this:

  chkReadOnly

The names you give to forms and controls:

  • must begin with a letter.

  • must contain only letters, numbers, and the underscore character (_); punctuation characters and spaces are not allowed.

  • must be no longer than 40 characters.

For More Information   See "Visual Basic Coding Conventions" for more information on naming conventions.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”