Visual Basic Concepts
Object Naming Conventions
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 |
ADO Data | ado | adoBiblio |
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 | dat | datBiblio |
Data-bound combo box | dbcbo | dbcboLanguage |
Data-bound grid | dbgrd | dbgrdQueryResult |
Data-bound list box | dblst | dblstJobType |
Data combo | dbc | dbcAuthor |
Data grid | dgd | dgdTitles |
Data list | dbl | dblPublisher |
Data repeater | drp | drpLocation |
Date picker | dtp | dtpPublished |
Directory list box | dir | dirSource |
Drive list box | drv | drvTarget |
File list box | fil | filSource |
Flat scroll bar | fsb | fsbMove |
Form | frm | frmEntry |
Frame | fra | fraLanguage |
Gauge | gau | gauStatus |
Graph | gra | graRevenue |
Grid | grd | grdPrices |
Hierarchical flexgrid | flex | flexOrders |
Horizontal scroll bar | hsb | hsbVolume |
Image | img | imgIcon |
Image combo | imgcbo | imgcboProduct |
ImageList | ils | ilsAllIcons |
Label | lbl | lblHelpMessage |
Lightweight check box | lwchk | lwchkArchive |
Lightweight combo box | lwcbo | lwcboGerman |
Lightweight command button | lwcmd | lwcmdRemove |
Lightweight frame | lwfra | lwfraSaveOptions |
Lightweight horizontal scroll bar | lwhsb | lwhsbVolume |
Lightweight list box | lwlst | lwlstCostCenters |
Lightweight option button | lwopt | lwoptIncomeLevel |
Lightweight text box | lwtxt | lwoptStreet |
Lightweight vertical scroll bar | lwvsb | lwvsbYear |
Line | lin | linVertical |
List box | lst | lstPolicyCodes |
ListView | lvw | lvwHeadings |
MAPI message | mpm | mpmSentMessage |
MAPI session | mps | mpsSession |
MCI | mci | mciVideo |
Menu | mnu | mnuFileOpen |
Month view | mvw | mvwPeriod |
MS Chart | ch | chSalesbyRegion |
MS Flex grid | msg | msgClients |
MS Tab | mst | mstFirst |
OLE container | ole | oleWorksheet |
Option button | opt | optGender |
Picture box | pic | picVGA |
Picture clip | clp | clpToolbar |
ProgressBar | prg | prgLoadFile |
Remote Data | rd | rdTitles |
RichTextBox | rtf | rtfReport |
Shape | shp | shpCircle |
Slider | sld | sldScale |
Spin | spn | spnPages |
StatusBar | sta | staDateTime |
SysInfo | sys | sysMonitor |
TabStrip | tab | tabOptions |
Text box | txt | txtLastName |
Timer | tmr | tmrAlarm |
Toolbar | tlb | tlbActions |
TreeView | tre | treOrganization |
UpDown | upd | updDirection |
Vertical scroll bar | vsb | vsbRate |
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 | ix | 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.