 |
|
Control Naming Conventions
When you first create
an object (form or control), Visual
Basic sets its Name property
to a default value. For example, all command buttons have their
Name property initially set to
Commandn, where n is 1, 2, 3, and so on. Visual Basic names
the first command button drawn on a form Command1, the second
Command2, and the third Command3.
You may choose to keep
the default name; however, when you have several controls of the
same type, it makes sense to change their Name properties to something more
descriptive. Because it may be difficult to distinguish the
Command1 button on MyForm from the Command1 button on YourForm, a
naming convention can help. This is especially true when an
application consists of several form, standard, and class
modules.
You can use a prefix to
describe the class, followed by a descriptive name for the control.
Using this naming convention makes the code more self-descriptive
and alphabetically groups similar objects in the Object list box.
For example, you might name a Check Box control like
this:
chkReadOnly
Therefore if
you had a Text Box that will hold a date, it's advisable to change
its name to "txtDate". Other prefixes include:
|
Picture
|
pic (e.g. picOpen)
|
|
ComboBox
|
cbo (e.g.
cboProductCodes)
|
|
CommandButton
|
cmd (e.g. cmdOK)
|
| Form |
frm (e.g. frmOrders)
|
|
Checkbox
|
chk (e.g. chkExtraCheese)
|
|
OptionButton
|
opt (e.g. optPlanTwo)
|
|
Label
|
lbl (e.g. lblName)
|
|
Text box
|
txt (e.g. txtDate)
|
|
List
|
lst (e.g. lstItems)
|
|
Scroll bar
|
scr (e.g. scrLeft)
|
|
Timer
|
tmr (e.g. tmrRefresh)
|
|
Drive
|
drv (e.g. drvDrives)
|
|
Directory list
|
dir (e.g. dirFolders)
|
|
File list
|
fil (e.g. filFiles)
|
|
Image
|
img (e.g. imgExit)
|
|
Line
|
ln (e.g. Line)
|
|
Shape
|
shp (e.g. shpSquare)
|
|