Datasheet

Figure 1-16
Now before you finish your sample application, let us briefly discuss some coding practices that you
should be using.
Modified Hungarian Notation
You may have noticed that the names given to the controls look a little funny. Each name is prefixed
with a shorthand identifier describing the type of control it is. This makes it much easier to understand
what type of control you are working with when you are looking through the code. For example, say
you had a control called simply Name, without a prefix of
lbl or txt. You would not know whether
you were working with a text box that accepted a name or with a label that displayed a name. Imagine
if, in the previous Try It Out, you had named your label Name1 and your text box Name2 you would
very quickly become confused. What if you left your application for a month or two and then came back
to it to make some changes?
When working with other developers, it is very important to keep the coding style consistent. One of the
most commonly used styles for control names within application development in many languages was
brought forth by Dr. Charles Simonyi, who worked for the Xerox Palo Alto Research Center (XPARC)
before joining Microsoft. He came up with short prefix mnemonics that allowed programmers to easily
identify the type of information a variable might contain. Since Simonyi is from Hungary, and the pre-
fixes make the names look a little foreign, the name “Hungarian Notation” came into use for this system.
Because the original notation was used in C/C++ development, the notation for Visual Basic 2005 is
termed Modified. The following table shows some of the commonly used prefixes that you shall be
using in this book.
Hungarian Notation can be a real time-saver when you are looking at code someone else wrote or at
code that you wrote months earlier. However, by far the most important thing is to be consistent in your
naming. When you start coding, pick a convention for your naming. It is recommended that you use the
de facto standard Modified-Hungarian for Visual Basic 2005, but it is not required. Once you pick a con-
vention, stick to it. When modifying others’ code, use theirs. A standard naming convention followed
throughout a project will save countless hours when the application is maintained. Now let’s get back to
the application. It’s now time to write some actual code.
17
Welcome to Visual Basic 2005
04_574019 ch01.qxd 9/16/05 9:43 PM Page 17