Share via


Visual Basic Concepts

Control Naming Conventions

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.