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 pnlGroup

Animated button ani aniMailBox

Check box chk chkReadOnly

Combo box, drop-down list box cbo cboEnglish

Command button cmd cmdExit

Common dialog dlg dlgFileOpen

Communications com comFax

Control (used within procedures when the specific type is unknown) ctr ctrCurrent

Data control dat datBiblio

Data-bound combo box dbcbo dbcboLanguage

Data-bound grid dbgrd dbgrdQueryResult

Data-bound list box dblst dblstJobType

Directory list box dir dirSource

Drive list box drv drvTarget

File list box fil filSource

Form frm frmEntry

Frame fra fraLanguage

Gauge gau gauStatus

Graph gra graRevenue

Grid grd grdPrices

Horizontal scroll bar hsb hsbVolume

Image img imgIcon

Key status key keyCaps

Label lbl lblHelpMessage

Line lin linVertical

List box lst lstPolicyCodes

MAPI message mpm mpmSentMessage

MAPI session mps mpsSession

MCI mci mciVideo

MDI child form mdi mdiNote

Menu mnu mnuFileOpen

MS Flex grid msg msgClients

MS Tab mst mstFirst

OLE ole oleWorksheet

Outline out outOrgChart

Pen BEdit bed bedFirstName

Pen HEdit hed hedSignature

Pen ink ink inkMap

Picture pic picVGA

Picture clip clp clpToolbar

Report rpt rptQtr1Earnings

Shape shp shpCircle

Spin spn spnPages

Text box txt txtLastName

Timer tmr tmrAlarm

UpDown upd updDirection

Vertical scroll bar vsb vsbRate

Slider sld sldScale

ImageList ils ilsAllIcons

TreeView tre treOrganization

Toolbar tlb tlbActions

TabStrip tab tabOptions

StatusBar sta staDateTime

ListView lvw lvwHeadings

ProgressBar prg prgLoadFile

RichTextBox rtf rtfReport

Suggested Prefixes for Data Access Objects (DAO)

Use the following prefixes to indicate Data Access Objects.

Database object Prefix Example

Container con conReports

Database db dbAccounts

DBEngine dbe dbeJet

Document doc docSalesReport

Field fld fldAddress

Group grp grpFinance

Index idx idxAge

Parameter prm prmJobCode

QueryDef qry qrySalesByRegion

Recordset rec recForecast

Relation rel relEmployeeDept

TableDef tbd tbdCustomers

User usr usrNew

Workspace 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 name

File Open mnuFileOpen

File Send Email mnuFileSendEmail

File Send Fax mnuFileSendFax

Format Character mnuFormatCharacter

Help 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.