Variables are used to hold values. With that goal in mind, 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 be able to keep track of its variables. Here, we offer some things to keep in mind, including standards.
First, you'll want to keep your naming consistent. So, 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.
Second, it is useful to include the scope of a variable by prefixing with g for global, or l for local (to a subprocedure), for example, gstrCompanyName and lstrDepartmentName .
Finally, 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.
Here 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 |
Here is a listing of control types and their associated Hungarian prefixes, complete with examples of use.
Control Type | Hungarian Prefix | Example |
Animated button |
Ani |
AniButton |
Check box |
Chk |
ChkNo |
Combo list box |
Cbo |
CboOS |
Command button |
Cmd |
CmdSend |
Common dialog |
Dlg |
DlgOpen |
Frame |
Fra |
FraOptions |
Horizontal scroll bar |
Hsb |
HsbContrast |
Image control |
Img |
ImgHeading |
Label |
Lbl |
LblText |
Line |
Lin |
LinDivide |
List box |
Lst |
LstDueBy |
3D panel |
Pnl |
PnlMain |
Pop-up menu |
Mnu |
MnuContextSelect |
Radio/Option button |
Opt |
OptIncludeFreeGift |
Slider |
Sld |
SldSetVolume |
Spin button |
Spn |
SpnCounter |
Tab strip |
Tab |
TabOptions |
Text box |
Txt |
TxtComment |
Vertical scroll bar |
Vsb |
VsbSetVolume |
Introduction