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.
Variable Scope Prefixes
As project size grows, so does the value of recognizing variable scope quickly. A one-letter scope prefix preceding the type prefix provides this, without greatly increasing the size of variable names.
Scope | Prefix | Example |
Global | g | gstrUserName |
Module-level | m | mblnCalcInProgress |
Local to procedure | None | dblVelocity |
A variable has global scope if it is declared Public in a standard module or a form module. A variable has module-level scope if declared Private in a standard module or form module, respectively.
Note Consistency is crucial to productive use of this technique; the syntax checker in Visual Basic will not catch module-level variables that begin with "p."
Constants
The body of constant names should be mixed case with capitals initiating each word. Although standard Visual Basic constants do not include data type and scope information, prefixes like i, s, g, and m can be very useful in understanding the value and scope of a constant. For constant names, follow the same rules as variables. For example:
mintUserListMax 'Max entry limit for User list
'(integer value,local to module)
gstrNewLine 'New Line character
'(string, global to application)
Variables
Declaring all variables saves programming time by reducing the number of bugs caused by typos (for example, aUserNameTmp vs. sUserNameTmp vs. sUserNameTemp). On the Editor tab of the Options dialog, check the Require Variable Declaration option. The Option Explicit statement requires that you declare all the variables in your Visual Basic program.
Variables should be prefixed to indicate their data type. Optionally, especially for large programs, the prefix can be extended to indicate the scope of the variable.
Variable Data Types
Use the following prefixes to indicate a variable's data type.
Data type | Prefix | Example |
Boolean | bln | blnFound |
Byte | byt | bytRasterData |
Collection object | col | colWidgets |
Currency | cur | curRevenue |
Date (Time) | dtm | dtmStart |
Double | dbl | dblTolerance |
Error | err | errOrderNum |
Integer | int | intQuantity |
Long | lng | lngDistance |
Object | obj | objCurrent |
Single | sng | sngAverage |
String | str | strFName |
User-defined type | udt | udtEmployee |
Variant | vnt | vntCheckSum |
v Variable passed by value (local to a routine)
r Variable passed by reference (local to a routine)
0 comentários: Notação Húngara
Postar um comentário