Objects should be named with a consistent prefix that makes it easy to identify the type of object. Recommended conventions for some of the objects supported by Visual Basic are listed below.
Suggested Prefixes for Controls
Control type
Prefix Example
3D Panel
pnl pnlGroupAnimated button
ani aniMailBoxCheck box
chk chkReadOnlyCombo box, drop-down list box
cbo cboEnglishCommand button
cmd cmdExitCommon dialog
dlg dlgFileOpenCommunications
com comFaxControl (used within procedures when the specific type is unknown)
ctr ctrCurrentData control
dat datBiblioData-bound combo box
dbcbo dbcboLanguageData-bound grid
dbgrd dbgrdQueryResultData-bound list box
dblst dblstJobTypeDirectory list box
dir dirSourceDrive list box
drv drvTargetFile list box
fil filSourceForm
frm frmEntryFrame
fra fraLanguageGauge
gau gauStatusGraph
gra graRevenueGrid
grd grdPricesHorizontal scroll bar
hsb hsbVolumeImage
img imgIconKey status
key keyCapsLabel
lbl lblHelpMessageLine
lin linVerticalList box
lst lstPolicyCodesMAPI message
mpm mpmSentMessageMAPI session
mps mpsSessionMCI
mci mciVideoMDI child form
mdi mdiNoteMenu
mnu mnuFileOpenMS Flex grid
msg msgClientsMS Tab
mst mstFirstOLE
ole oleWorksheetOutline
out outOrgChartPen BEdit
bed bedFirstNamePen HEdit
hed hedSignaturePen ink
ink inkMapPicture
pic picVGAPicture clip
clp clpToolbarReport
rpt rptQtr1EarningsShape
shp shpCircleSpin
spn spnPagesText box
txt txtLastNameTimer
tmr tmrAlarmUpDown
upd updDirectionVertical scroll bar
vsb vsbRateSlider
sld sldScaleImageList
ils ilsAllIconsTreeView
tre treOrganizationToolbar
tlb tlbActionsTabStrip
tab tabOptionsStatusBar
sta staDateTimeListView
lvw lvwHeadingsProgressBar
prg prgLoadFileRichTextBox
rtf rtfReport
Suggested Prefixes for Data Access Objects (DAO)
Use the following prefixes to indicate Data Access Objects.
Database object
Prefix Example
Container
con conReportsDatabase
db dbAccountsDBEngine
dbe dbeJetDocument
doc docSalesReportField
fld fldAddressGroup
grp grpFinanceIndex
idx idxAgeParameter
prm prmJobCodeQueryDef
qry qrySalesByRegionRecordset
rec recForecastRelation
rel relEmployeeDeptTableDef
tbd tbdCustomersUser
usr usrNewWorkspace
wsp wspMine
Some examples:
Dim dbBiblio As Database
Dim recPubsInNY As Recordset, strSQLStmt As String
Const DB_READONLY = 4
' Set constant.'Open database.
Set dbBiblio = OpenDatabase("BIBLIO.MDB")
' Set text for the SQL statement.
strSQLStmt = "SELECT * FROM Publishers WHERE _
State = 'NY'"
' Create the new Recordset object.
Set recPubsInNY = db.OpenRecordset(strSQLStmt, _
dbReadOnly)
Suggested Prefixes for Menus
Applications frequently use many menu controls, making it useful to have a unique set of naming conventions for these controls. Menu control prefixes should be extended beyond the initial "mnu" label by adding an additional prefix for each level of nesting, with the final menu caption at the end of the name string. The following table lists some examples.
Menu caption sequence
Menu handler nameFile Open
mnuFileOpenFile Send Email
mnuFileSendEmailFile Send Fax
mnuFileSendFaxFormat Character
mnuFormatCharacterHelp Contents
mnuHelpContents
When this naming convention is used, all members of a particular menu group are listed next to each other in Visual Basic’s Properties window. In addition, the menu control names clearly document the menu items to which they are attached.
Choosing Prefixes for Other Controls
For controls not listed above, you should try to standardize on a unique two or three character prefix for consistency. Use more than three characters only if needed for clarity.
For derived or modified controls, for example, extend the prefixes above so that there is no confusion over which control is really being used. For third-party controls, a lower-case abbreviation for the manufacturer could be added to the prefix. For example, a control instance created from the Visual Basic Professional 3D frame could uses a prefix of fra3d to avoid confusion over which control is really being used.