Visual Basic

Naming Conventions

We use a simplified form of Hungarian notation, a naming convention that takes its name from the nationality of its creator, Charles Simonyi. Certain elements of Hungarian notation are used in Microsoft's Visual Basic manuals. Microsoft also uses Hungarian notation internally as part of its coding conventions, as do many developers around the world. Our simplified form of this notation is used to attach both type and scope information to various object names. Hungarian notation uses character prefixes to denote type, aggregation, and scope, and the full system gets rather complicated. The subset we've chosen for our purposes is defined in the following sections and in the tables that appear at the end of this appendix.

Type Information

Hungarian type prefixes have two parts: a base type to represent the base data type and a modifier to denote an aggregate type. An example of a base-type prefix is n, which denotes an integer, while adding the a modifier to the base type denotes an array of integers. An example should make this clearer:

  Dim nCounter            As Integer
  Dim anCounters(1 To 10) As Integer

Notice that the variable name itself starts with an uppercase letter, which shows us where the prefix stops and the variable name starts. Sometimes we need to use more than one modifier, such as a multidimensional array:

  Dim aanStateTable(1 To 10, 1 To 10) As Integer

The base types and modifiers we use are listed at the end of this appendix. In fact, we use only one aggregate modifier since arrays are the only single-type aggregates that Visual Basic supports.

Where calls are made to Windows API functions, you might see type prefixes such as LPSTR and sz that don't appear in our tables: these prefixes are used in the Microsoft Windows documentation. We've found that changing these to match our Visual Basic data types can often conceal errors in the declarations. You might also see p used as a modifier to denote a pointer and pcb to denote the address of a callback function.

For variables defined with user-defined types (UDTs) and classes, the special base-type prefixes t and C are used. Although C breaks the lowercase rule, we've adopted it because it's used throughout the industry.

Menus are named with the type prefix mnu, but the names are aggregated to show the menu structure. For example, the Open item on the File menu is called mnuFileOpen. Here are some more standard menu names:

  mnuHelpAbout
  mnuFileExit