Partager via


Visual Basic Concepts

Naming Properties, Methods, and Events

The properties, methods, and events you add to a class module define the interface that will be used to manipulate objects created from the class. When naming these elements, and their arguments, you may find it helpful to follow a few simple rules.

  • Use entire words whenever possible, as for example SpellCheck. Abbreviations can take many forms, and hence can be confusing. If whole words are too long, use complete first syllables.

  • Use mixed case for your identifiers, capitalizing each word or syllable, as for example ShortcutMenus or AsyncReadComplete.

  • Use the correct plural for collection class names, as for example Worksheets, Forms, or Widgets. If the collection holds objects with a name that ends in "s," append the word "Collection," as for example SeriesCollection.

  • Use either verb/object or object/verb order consistently for your method names. That is, use InsertWidget, InsertSprocket, and so on, or always place the object first, as in WidgetInsert and SprocketInsert.

Note   While it’s possible to use an underscore character in a property name, an underscore in an event name will cause an error. The underscore character is used in Event procedures to separate the event name from the object name. For this reason, it’s best to avoid the underscore character altogether when naming properties, methods, and events.

One of the chief benefits of programming with objects is code reuse. Following the rules above, which are part of the ActiveX guidelines for interfaces, makes it easier to remember the names and purposes of properties, methods, and events.

For More Information*   If you have the Professional or Enterprise Edition of Visual Basic, see the expanded list in "What's In a Name?" in "General Principles of Component Design" in Creating ActiveX Components in the *Component Tools Guide.