Hungarian Notation
This document details standard Hungarian notation. This discussion of Hungarian differs from other Hungarian notation outlines in that the types have been assigned with both Visual Basic and C/C++ in mind. The intention is to supply a notation encompassing both languages.
Hungarian notation can be used to reduce variable ambiguity and increase code clarity. While it can be argued that the use of Hungarian notation under C/C++ is an individual preference, under Visual Basic a naming convention can help avoid a syntactic ambiguity. C/C++ member function calls and member variable access can be differentiated by the existence of parenthesis for member function calls, however, this is not true in Visual Basic. Access to user defined type members is syntactically indistinguishable from access to control properties without using a naming convention.
Engineers are not limited to the types provided. However, new types should not conflict with the standard notation. In addition, strict adherence to the base types is not required, but recommended. Although consistency is the key for Hungarian notation, deviations from the standard base types must be consistent throughout. For example, historically, some languages used "i" and "j" as default integer variables. Many engineers use "i" as a nondescript loop counter even though this deviates from the standard notation. If used consistently, this deviation is acceptable.
All variable names are composed of three elements: prefixes, base type, and qualifier. The base type is required while the prefixes and qualifiers are optional. The base type is a mnemonic used to identify the variable type. In cases where the base type is not specific enough to identify the variable type or to specify variable scope, prefix mnemonics should be used. The qualifier is used to distinguish variables of the same type. A qualifier is a word or text fragment descriptive of the variable’s intended function.
Table 1: Prefix, base, and qualifier examples
| Variable |
Prefix |
Base |
Qualifier |
| nTotal |
prefix is omitted indicating a variable of local scope. |
n is the base indicating an integer. |
Total is the qualifier. |
| gkMegabyte |
g is the prefix indicating a variable of global scope. |
k is the base indicating a constant. |
Megabyte is the qualifier. |
| s |
prefix is omitted indicating a variable of local scope. |
s is the base indicating a string. |
qualifier is omitted indicating a temporary or multi-use variable. |
The base type is a mnemonic used to identify the variable type. The standard base types for intrinsic data types are given in the table below. Engineers may create their own base types if required. However, new base types should not conflict with the standard base types.
The standard base types have been assigned with both Visual Basic and C/C++ in mind. Data types available in both languages have been given the same base type whenever possible regardless of actual data implementation sizes. The Visual Basic base type table contains the default suffix for informational purposes only. Our software standards for Visual Basic requires explicit variable declaration.
Table 2: Standard Variable Bases
| Base |
Data Type |
C/C++ |
Visual Basic |
VB Suffix |
| b |
byte |
unsigned char b; |
dim b as string * 1 OR dim b as byte |
|
| c |
char |
char c; |
dim c as string * 1 |
|
| col |
collection |
|
dim col as new Collection |
|
| cur |
currency |
|
dim cur as currency |
@ |
| d |
double |
double d; |
dim d as double |
# |
| e |
float, single |
float e; |
dim e as single |
! |
| f |
flag (boolean or logical) |
int f; |
dim f as integer OR dim f as boolean |
|
| fn |
function |
|
|
|
| h |
handle |
HWND hwnd; |
dim hwnd as integer |
|
| k |
constant (#defines, enums, const) |
#define k = 2 |
const k = 2 |
|
| l |
long |
long l; |
dim l as long |
& |
| ld |
long double |
long double ld; |
|
|
| n |
int, short, integer |
int i; short i; |
dim n as integer |
% |
| o |
object |
Object o; |
dim o as new Object |
|
| s |
string |
|
dim s as string |
$ |
| sz |
null terminated string |
char sz[10]; |
dim sz as string |
|
| t |
user defined type (structure, typedef, type) |
UserType t; |
dim t as UserType |
|
| uc |
unsigned char |
unsigned char uc; |
dim uc as string * 1 |
|
| ul |
unsigned long |
unsigned long ul; |
|
|
| un |
unsigned int |
unsigned int un; |
|
|
| v or vd |
void |
void *v; |
|
|
| v or vnt |
variant |
|
dim v as variant |
|
| w |
word |
WORD w; |
dim w as integer |
|
Table 3: Standard Control Bases, new items are in bold
| Base |
Control Type |
|
|
Base |
Control Type |
| ani |
Animation |
|
|
mhint |
Microhelp Integer Edit |
| bed |
Pen Bedit |
|
|
mhlst |
Microhelp 3D Listbox |
| brw |
VB5 WebBrowser |
|
|
mhrel |
Microhelp Real Edit |
| cbo |
Combobox and dropdown Listbox |
|
|
mnu |
Menu |
| chk |
Checkbox |
|
|
mpm |
MAPI Message |
| cht |
VB5 MS Chart |
|
|
mps |
MAPI Session |
| clp |
Picture Clip |
|
|
ole |
Ole Client |
| cmd |
Command Button |
|
|
opt |
Option Button |
| com |
Communications |
|
|
out |
Outline Control |
| ctl |
Control (specific type is unknown) |
|
|
pic |
Picture |
| dat |
Data |
|
|
pnl |
3d Panel (threed) |
| dbcbo |
Apex DbCombo |
|
|
prg |
VB5 ProgressBar |
| dbg |
Apex DbGrid |
|
|
rdc |
VB5 Remote Data Control |
| dir |
Directory List Box |
|
|
rpt |
Report Control |
| dlg |
Common Dialog |
|
|
rtx |
VB5 RichText |
| drv |
Drive List Box |
|
|
sb |
VB5 Statusbar |
| eas |
Lassalle EasyNet drawing control |
|
|
shp |
Shape (circle, square, oval, ...) |
| els |
Videosoft Elastic |
|
|
sld |
VB5 Slider |
| fil |
File List Box |
|
|
spn |
Spin Control |
| fpb |
Farpoint fpBoolean |
|
|
sstb |
SS Tab |
| fpc |
Farpoint fpCurrency |
|
|
sys |
VB5 SysInfo |
| fpds |
Farpoint fpDoubleSingle |
|
|
tb |
VB5 toolbar |
| fpdt |
Farpoint fpDateTime |
|
|
tbr |
Cockell Toolbar |
| fpli |
Farpoint fpLongInteger |
|
|
tbs |
VB5 Tabstrip |
| fpm |
Farpoint fpMemo |
|
|
tdbg |
Apex TrueDbGrid |
| fpmsk |
Farpoint fpMask |
|
|
tgrd |
Apex Truegrid |
| fptxt |
Farpoint fpText |
|
|
tip |
Cockell ToolTip |
| fra |
Frame |
|
|
tlst |
Bennett-Tec Tlist hierarchical listbox |
| frm |
Form |
|
|
tmr |
Timer |
| gau |
Gauge |
|
|
tnm |
Text Numeric (textBox) |
| gpb |
Group Push Button |
|
|
tv |
VB5 TreeView |
| gra |
Graphic Server Graph |
|
|
txt |
Text/Edit Box |
| grd |
Grid |
|
|
upd |
VB5 UpDown |
| hed |
Pen Hedit |
|
|
vcf |
Visual Components F1Book |
| hsb |
Horizontal Scroll Bar |
|
|
vcg |
Visual Components vtChart |
| img |
Image |
|
|
vfa |
Videosoft vsFlexArray |
| iml |
VB5 ImageList |
|
|
vfs |
Videosoft vsFlexString |
| ink |
Pen Ink |
|
|
vsb |
Vertical Scroll Bar |
| itb |
Videosoft Index tab |
|
|
vsd |
Videosoft vsDraw |
| itc |
VB5 Internet Transfer (Inet) |
|
|
vsi |
Videosoft vsInForm |
| key |
Keyboard key status |
|
|
vsp |
Videosoft vsPrinter |
| lbl |
Label |
|
|
vsr |
Videosoft vsReport |
| lin |
Line |
|
|
vsv |
Videosoft vsViewPort |
| lst |
Listbox |
|
|
wsk |
VB5 Winsock |
| lv |
VB5 ListView |
|
|
|
|
| mci |
MCI |
|
|
|
|
| med |
Masked Edit |
|
|
|
|
| mhdat |
MicroHelp Date Edit |
|
|
|
|
Table 4: Standard Data Access Object (DAO) Bases
| Base |
DAO Type |
|
|
Base |
DAO Type |
| con |
Container |
|
|
prm |
Parameter |
| db |
Database |
|
|
qry |
QueryDef |
| dbe |
DBEngine |
|
|
rec |
Recordset |
| doc |
Document |
|
|
rel |
Relation |
| ds |
Dynaset |
|
|
tbd |
TableDef or Table |
| fld |
Field |
|
|
usr |
User |
| grp |
Group |
|
|
wsp |
Workspace |
| idx |
Index |
|
|
|
|
In cases where the base type is not specific enough to identify the variable type or to specify variable scope, prefix mnemonics should be used.
Table 5: Standard Variable Prefixes
| Prefix |
Definition |
C/C++ |
Visual Basic |
| g |
global scope |
Yes |
Yes |
| m |
module/form global or static |
Yes |
Yes |
| p |
pointer |
Yes |
|
| lp |
long pointer |
Yes |
|
| hp |
huge pointer |
Yes |
|
| i |
index into an array |
Yes |
Yes |
| a |
array |
Yes |
Yes |
The array prefix (a) is most often used when accessing an array with a pointer,
ie. paszNames is a pointer to an array of null terminated strings. Often the array prefix is omitted when not using a pointer,
ie. gtModel(0).sName = "Hello" is a reference to a global array of some
user defined type. The element subscript access (0) can be sufficient.
The qualifier is used to distinguish variable of the same type. A qualifier
is a word or text fragment descriptive of the variable’s intended function.
The qualifier should use mixed case or underscores within itself and to separate itself from the base.
Table 6: Standard Variable Qualifiers
| Qualifier |
Definition |
| First |
first element to deal with in a set |
| Last |
last element to deal with in a set |
| Lim |
upper limit of a set, an invalid element; equal to Last + 1 |
| Min |
first element in a set |
| Max |
last element in a set |
| Sav or Tmp |
temporary value |
| Nil |
illegal value |
| Null |
zero |
| Src |
a source |
| Dst |
a destination |
| Data |
general purpose item |
The following table contains examples of Hungarian notation.
Table 7: Hungarian Notation Examples
| Variable |
Definition |
| nTotal |
integer named Total |
| szTitle |
null terminated string named Title |
| sResults |
string named Results |
| pcSelectChar |
pointer to character named SelectChar |
| anValues or nValues(i) |
array of integers named Values |
| tCar |
structure named Car |
| atCar or tCar(i) |
array of structures named Car |
| iCurCar |
array index named CurCar |
| gkMegabyte |
global constant named Megabyte |
| mnSelected |
module/form global or static integer named Selected |
| lpfnTask |
long pointer to a function named Task |
| hWnd |
handle named Wnd |
| eSum |
float or single named Sum |
| fState |
flag (boolean or logical) named State |
| gksSection |
global constant string named Section |
| dValue |
double named Value |
| vSrc |
a variant named Src that indicates a source by using a standard qualifier |
| vDst |
a variant named Src that indicates a destination by using a standard qualifier |
|