Appendix B. Variable Naming Convention

Because variables are used to hold values, it makes sense to choose names for them that describe their purpose or what they contain. The bigger the project you are working on is, the more important it is to keep track of its variables. This appendix offers some things to keep in mind, including standards:

  • You'll want to keep your naming consistent. For example if you use Cnt as a variable in one part of the script and Count in another when you are in fact dealing with the same data, you're very likely to introduce runtime errors by confusing the variables.

  • It is useful to include the scope of a variable by prefixing it with g for global, or l for local (to a subprocedure), such as gstrCompanyName and lstrDepartmentName.

  • One of the best ways to organize variable names is to prefix all variable names you use with a shorthand representation of the data type that the variable will hold. The standard prefixes used to accomplish this are called Hungarian notation.

Following is a listing of data types and their associated Hungarian prefixes, complete with examples of use.

Data Type

Hungarian Prefix

Example

VarType()

Boolean

bln (or bool)

BlnValid

11

Byte

Byt

bytColor

17

Currency

Cur

CurTotal

6

Date or Time

Dtm

dtmMember

7

Double

Dbl

DblTotal

5

Error

Err

errInvalidEmailAddress

10

Integer

Int

intCount

2

Long

Lng

lngHeight

3

Object

Obj

ObjWS

9 or 13

Single

Sng

sngWidth

4

String

Str

strName

8

Variant

Var

varNumber

12

Following is a listing of control types and their associated Hungarian prefixes, complete with ...

Get VBScript Programmer's Reference, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.