Variable prefixes

Much of the confusion in current Hungarian variations comes from trying to make the prefix do too many conflicting things. At various times, I’ve seen the pre­fix used to indicate several different concepts. Even if you don’t buy into Hungarian, any naming convention must deal with some of the following
elements:

What I’m creating here is a more portable Hungarian that works for Basic. I often don’t care what type a variable has when I use it; I’m much more interested in whether a handle is a handle to a window, a file, or a GDI object than in what data type it is. I use integers for different purposes: counts, indexes, handles, ordinals, and bit fields. Whether they are Longs or Integers usually doesn’t matter after the declaration. If I need to know, I can always go back to the declaration and check.

The point of Hungarian is not to be an absolute standard for everyone but to be standard across a given department, project, program, or, in this case, book. I’ve used the conventions defined in Table 1-2 throughout (consistently, I hope).

Some prefixes modify other prefixes. For example, acmd is an array of buttons, ccmd is a count of buttons, and ncmd is a collection of buttons. Strict Hungarian always uses c as a modifier. You could use ciWindow as a count of indexes to windows or chWindow as a count of handles to windows, but I often find that I can make the meaning clearer by omitting the second part of the prefix. If I’m counting windows, cWindow is sufficient.

I’ll introduce and explain some additional conventions later in the book. In particular, some of the new object-oriented features of Visual Basic require further discussion and variations.

Prefix Variable or Object
i integer index (type Integer or Long)
h handle
ord ordinal (a numeric identification code used when the specific value is unimportant except to distinguish the variable from others)
x, y x and y coordinates of points
dx, dy delta (or distance) in terms of x and y coordinates (dx is width, dy is height)
f Boolean
af bit flag (an array of Booleans represented by bits)
r real number (either Single or Double)
b Byte
v Variant
cur Currency
time time
date Date
dt Date and time combined
s String
p pointer (Long variable from or for an API function)
cmd button
chk check box
txt text box
pb picture box
pic picture
lst list box
cbo combo box
lbl label
mnu menu
tmr timer
opt option button (radio button)
c count
A array
N collection

Table 1-2. Hardcore Hungarian for variables.