Article ID: 110264
Article Last Modified on 1/9/2003
Prefix Object Type Example ------------------------------------------------------- ani Animation button aniMailBox bed Pen Bedit bedFirstName cbo Combo box and drop down list box cboEnglish chk Checkbox chkReadOnly clp Picture clip clpToolbar cmd (3d) Command button (3D) cmdOk (cmd3dOk) com Communications comFax ctr Control (when specific type unknown) ctrCurrent dat Data control datBiblio dir Directory list box dirSource dlg Common dialog control dlgFileOpen drv Drive list box drvTarget fil File list box filSource frm Form frmEntry fra (3d) Frame (3d) fraStyle (fra3dStyle) gau Gauge gauStatus gpb Group push button gpbChannel gra Graph graRevenue grd Grid grdPrices hed Pen Hedit hedSignature hsb Horizontal scroll bar hsbVolume img Image imgIcon ink Pen Ink inkMap key Keyboard key status keyCaps lbl Label lblHelpMessage lin Line linVertical lst List box lstPolicyCodes mdi MDI child form mdiNote mpm MAPI message mpmSentMessage mps MAPI session mpsSession mci MCI mciVideo mnu Menu mnuFileOpen opt (3d) Option Button (3d) optRed (opt3dRed) ole OLE control oleWorksheet out Outline control outOrgChart pic Picture picVGA pnl3d 3d Panel pnl3d rpt Report control rptQtr1Earnings shp Shape controls shpCircle spn Spin control spnPages txt Text Box txtLastName tmr Timer tmrAlarm vsb Vertical scroll bar vsbRate
Prefix Object Type Example ------------------------------------------ db ODBC Database dbAccounts ds ODBC Dynaset object dsSalesByRegion fdc Field collection fdcCustomer fd Field object fdAddress ix Index object ixAge ixc Index collection ixcNewAge qd QueryDef object qdSalesByRegion qry (suffix) Query (see NOTE) SalesByRegionQry ss Snapshot object ssForecast tb Table object tbCustomer td TableDef object tdCustomersNOTE: Using a suffix for queries allows each query to be sorted with its associated table in Microsoft Access dialogs (Add Table, List Tables Snapshot).
Menu Caption Sequence Menu Handler Name Help.Contents mnuHelpContents File.Open mnuFileOpen Format.Character mnuFormatCharacter File.Send.Fax mnuFileSendFax File.Send.Email mnuFileSendEmailWhen this convention is used, all members of a particular menu group are listed next to each other in the object drop-down list boxes (in the code window and property window). In addition, the menu control names clearly document the menu items to which they are attached.
Prefix Control Type Vendor cmdm Command Button MicroHelp
Part Description Example -------------------------------------------------------------------------- <prefix> Describes the use and scope of the variable. iGetRecordNext <body> Describes the variable. iGetNameFirst <qualifier> Denotes a derivative of the variable. iGetNameLast <suffix> The optional Visual Basic type character. iGetRecordNext%Prefixes:
Prefix Converged Variable Use Data Type Suffix
--------------------------------------------------------------------------
b bln Boolean Integer %
c cur Currency - 64 bits Currency @
d dbl Double - 64 bit Double #
signed quantity
dt dat Date and Time Variant
e err Error
f sng Float/Single - 32 Single !
bit signed
floating point
h Handle Integer %
i Index Integer %
l lng Long - 32 bit Long &
signed quantity
n int Number/Counter Integer %
s str String String $
u Unsigned - 16 bit Long &
unsigned quantity
udt User-defined type
vnt vnt Variant Variant
a Array
NOTE: the values in the Converged column represent efforts to pull together
the naming standards for Visual Basic, Visual Basic for Applications, and
Access Basic. It is likely that these prefixes will become Microsoft
standards at some point in the near future.
Prefix Description g Global m Local to module or form st Static variable (no prefix) Non-static variable, prefix local to procedure v Variable passed by value (local to a routine) r Variable passed by reference (local to a routine)Hungarian notation is as valuable in Visual Basic as it is in C. Although the Visual Basic type suffixes do indicate a variable's data type, they do not explain what a variable or function is used for, or how it can be accessed. Here are some examples:
iSend - Represents a count of the number of messages sent
bSend - A Boolean flag defining the success of the last Send operation
hSend - A Handle to the Comm interface
Qualifier Description (follows Body)
--------------------------------------------------------------------------
First First element of a set.
Last Last element of a set.
Next Next element in a set.
Prev Previous element in a set.
Cur Current element in a set.
Min Minimum value in a set.
Max Maximum value in a set.
Save Used to preserve another variable that must be reset later.
Tmp A "scratch" variable whose scope is highly localized within the
code. The value of a Tmp variable is usually only valid across
a set of contiguous statements within a single procedure.
Src Source. Frequently used in comparison and transfer routines.
Dst Destination. Often used in conjunction with Source.
Type CUSTOMER_TYPE
sName As String
sState As String * 2
lID as Long
End Type
When declaring an instance variable of a user defined type, add a prefix to
the variable name to reference the type. For example:
Dim custNew as CUSTOMER_TYPE
<mnUSER_LIST_MAX ' Max entry limit for User list (integer value,
' local to module)
gsNEW_LINE ' New Line character string (global to entire
' application)
Sub ConvertNulls(rvntOrg As Variant, rvntSub As Variant)
' If rvntOrg = Null, replace the Null with rvntSub
If IsNull(rvntOrg) Then rvntOrg = rvntSub
End Sub
The are some drawbacks, however, to using variants. Code statements that
use variants can sometimes be ambiguous to the programmer. For example:
vnt1 = "10.01" : vnt2 = 11 : vnt3 = "11" : vnt4 = "x4" vntResult = vnt1 + vnt2 ' Does vntResult = 21.01 or 10.0111? vntResult = vnt2 + vnt1 ' Does vntResult = 21.01 or 1110.01? vntResult = vnt1 + vnt3 ' Does vntResult = 21.01 or 10.0111? vntResult = vnt3 + vnt1 ' Does vntResult = 21.01 or 1110.01? vntResult = vnt2 + vnt4 ' Does vntResult = 11x4 or ERROR? vntResult = vnt3 + vnt4 ' Does vntResult = 11x4 or ERROR?The above examples would be much less ambiguous and easier to read, debug, and maintain if the Visual Basic type conversion routines were used instead. For Example:
iVar1 = 5 + val(sVar2) ' use this (explicit conversion) vntVar1 = 5 + vntVar2 ' not this (implicit conversion)
Section Comment Description
--------------------------------------------------------------------------
Purpose What the routine does (not how).
Inputs Each non-obvious parameter on a separate line with
in-line comments
Assumes List of each non-obvious external variable, control, open file,
and so on.
Returns Explanation of value returned for functions.
Effects List of each effected external variable, control, file, and
so on and the affect it has (only if this is not obvious)
Every non-trivial variable declaration should include an in-line comment
describing the use of the variable being declared.
**************************************************************************
'Purpose: Locate first occurrence of a specified user in UserList array.
'Inputs: rasUserList(): the list of users to be searched
' rsTargetUser: the name of the user to search for
'Returns: the index of the first occurrence of the rsTargetUser
' in the rasUserList array. If target user not found, return -1.
'**************************************************************************
'VB3Line: Enter the following lines as one line
Function iFindUser (rasUserList() As String, rsTargetUser as String) _
As Integer
Dim i As Integer ' loop counter
Dim bFound As Integer ' target found flag
iFindUser = -1
i = 0
While i <= Ubound(rasUserList) and Not bFound
If rasUserList(i) = rsTargetUser Then
bFound = True
iFindUser = i
End If
Wend
End Function
Variables and non-generic constants should be grouped by function rather
than by being split off into isolated areas or special files. Visual Basic
generic constants such as HOURGLASS should be grouped in a single module
(VB_STD.BAS) to keep them separate from application-specific declarations.
vntVar1 = "10.01" vntVar2 = 11 vntResult = vntVar1 + vntVar2 ' vntResult = 21.01 vntResult = vntVar1 & vntVar2 ' vntResult = 10.0111
Scope Variable Declared In: Visibility
--------------------------------------------------------------------------
Procedure-level Event procedure, sub, or Visible in the
function procedure in which
it is declared
Form-level, Declarations section of a form Visible in every
Module-level or code module (.FRM, .BAS) procedure in the
form or code
module
Global Declarations section of a code Always visible
module (.BAS, using Global
keyword)
In a Visual Basic application, only use global variables when there is no
other convenient way to share data between forms. You may want to consider
storing information in a control's Tag property, which can be accessed
globally using the form.object.property syntax.
Vendor Abbv ------------------------- MicroHelp (VBTools) m Pioneer Software p Crescent Software c Sheridan Software s Other (Misc) oThe following table lists standard third-party control prefixes:
Control Control Abbr Vendor Example VBX File
Type Name Name
--------------------------------------------------------------------------
Alarm Alarm almm MicroHelp almmAlarm MHTI200.VBX
Animate Animate anim MicroHelp animAnimate MHTI200.VBX
Callback Callback calm MicroHelp calmCallback MHAD200.VBX
Combo Box DB_Combo cbop Pioneer cbopComboBox QEVBDBF.VBX
Combo Box SSCombo cbos Sheridan cbosComboBox SS3D2.VBX
Check Box DB_Check chkp Pioneer chkpCheckBox QEVBDBF.VBX
Chart Chart chtm MicroHelp chtmChart MHGR200.VBX
Clock Clock clkm MicroHelp clkmClock MHTI200.VBX
Button Command cmdm MicroHelp cmdmCommandButton MHEN200.VBX
Button
Button DB_Command cmdp Pioneer cmdpCommandButton QEVBDBF.VBX
Button (Group) Command cmgm MicroHelp cmgmBtton MHGR200.VBX
Button
(multiple)
Button Command cmim MicroHelp cmimCommandButton MHEN200.VBX
Button
(icon)
CardDeck CardDeck crdm MicroHelp crdmCard MHGR200.VBX
Dice Dice dicm MicroHelp dicmDice MHGR200.VBX
List Box (Dir) SSDir dirs Sheridan dirsDirList SS3D2.VBX
List Box (Drv) SSDrive drvs Sheridan drvsDriveList SS3D2.VBX
List Box (File) File List film MicroHelp filmFileList MHEN200.VBX
List Box (File) SSFile fils Sheridan filsFileList SS3D2.VBX
Flip Flip flpm MicroHelp flpmButton MHEN200.VBX
Scroll Bar Form Scroll fsrm MicroHelp fsrmFormScroll ???
Gauge Gauge gagm MicroHelp gagmGauge MHGR200.VBX
Graph Graph gpho Other gphoGraph XYGRAPH.VBX
Grid Q_Grid grdp Pioneer grdpGrid QEVBDBF.VBX
Scroll Bar Horizontal hsbm MicroHelp hsbmScroll MHEN200.VBX
Scroll Bar
Scroll Bar DB_HScroll hsbp Pioneer hsbpScroll QEVBDBF.VBX
Graph Histo hstm MicroHelp hstmHistograph MHGR200.VBX
Invisible Invisible invm MicroHelp invmInvisible MHGR200.VBX
List Box Icon Tag itgm MicroHelp itgmListBox MHAD200.VBX
Key State Key State kstm MicroHelp kstmKeyState MHTI200.VBX
Label Label (3d) lblm MicroHelp lblmLabel MHEN200.VBX
Line Line linm MicroHelp linmLine MHGR200.VBX
List Box DB_List lstp Pioneer lstpListBox QEVBDBF.VBX
List Box SSList lsts Sheridan lstsListBox SS3D2.VBX
MDI Child MDI Control mdcm MicroHelp mdcmMDIChild ???
Menu SSMenu mnus Sheridan mnusMenu SS3D3.VBX
Marque Marque mrqm MicroHelp mrqmMarque MHTI200.VB
Picture OddPic odpm MicroHelp odpmPicture MHGR200.VBX
Picture Picture picm MicroHelp picmPicture MHGR200.VBX
Picture DB_Picture picp Pioneer picpPicture QEVBDBF.VBX
Property Vwr Property pvrm MicroHelp pvrmPropertyViewer MHPR200.VBX
Viewer
Option (Group) DB_RadioGroup radp Pioneer radqRadioGroup QEVBDBF.VBX
Slider Slider sldm MicroHelp sldmSlider MHGR200.VBX
Button (Spin) Spinner spnm MicroHelp spnmSpinner MHEN200.VBX
Spreadsheet Spreadsheet sprm MicroHelp sprmSpreadsheet MHAD200.VBX
Picture Stretcher strm MicroHelp strmStretcher MHAD200.VBX
Screen Saver Screen Saver svrm MicroHelp svrmSaver MHTI200.VBX
Switcher Switcher swtm MicroHelp swtmSwitcher ???
List Box Tag tagm MicroHelp tagmListBox MHEN200.VBX
Timer Timer tmrm MicroHelp tmrmTimer MHTI200.VBX
ToolBar ToolBar tolm MicroHelp tolmToolBar MHAD200.VBX
List Box Tree trem MicroHelp tremTree MHEN200.VBX
Input Box Input (Text) txtm MicroHelp inpmText MHEN200.VBX
Input Box DB_Text txtp Pioneer txtpText QEVBDBF.VBX
Scroll Bar Vertical vsbm MicroHelp vsbmScroll MHEN200.VBX
Scroll Bar
Scroll Bar DB_VScroll vsbp Pioneer vsbpScroll QEVBDBF.VBX
Keywords: kbinfo kbtophit kbref kbprogramming kbdocs kb3rdparty KB110264