How-to: The Reddick VBA Naming Conventions - Prefixes

Prefixes modify an object tag to indicate more information about an object.

Arrays of objects prefix

Arrays of an object type use the prefix “a”. For example:

aintFontSizes

astrNames

Index prefix

You indicate an index into an array by the prefix “i,” regardless of the datatype of the index. You can also use the index prefix to index into other enumerated objects, such as a collection of user-defined classes. For example:

iaintFontSizes

iastrNames

igphsGlyphCollection

Prefixes for scope and lifetime

Three levels of scope exist for each variable in VBA: Public, Private, and Local. A variable also has a lifetime of the current procedure or the length of the program. Use the prefixes in Table 2 to indicate scope and lifetime.

Table 2. Prefixes for scope and lifetime.

Prefix Object Type
(none) Local variable, procedure-level lifetime
s Local variable, program-level lifetime (static variable)
m Private (module) variable, program-level lifetime
g Public (global) variable, program-level lifetime

You also use the “m”" and “g” constants with other objects, such as constants, to indicate their scope. For example:

intLocalVariable

mintPrivateVariable

gintPublicVariable

mconPi

Other prefixes

Table 3 lists and describes some other prefixes.

Table 3. Other commonly-used prefixes.

Prefix Object Type
c Count of some object type
h Handle to a Windows object
r Parameter passed by reference

Here are several examples:

cstrArray

hwndForm

Copyright © 1995 Greg Reddick. You can freely distribute this document.

Related

  1. Introduction - Variable and Procedure names
  2. Prefixes
  3. Suffixes
  4. Object variables and DAO - variables
  5. Database Explorer objects - Table, Query, Form etc
  6. Object Names

 
Copyright © 1999-2024 SS64.com
Some rights reserved