使用的控件前缀

应该用一致的前缀来命名对象,使人们容易识别对象的类型。下面列出了 Visual Basic
支持的一些推荐使用的对象约定。

推荐使用的控件前缀

控件类型        前缀    例子

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 (当特定
类型未知时,在过
程中所使用的)  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

推荐使用的数据访问对象 (DAO) 的前缀
用下列前缀来指示数据访问对象。
数据库对象      前缀    例子

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

一些例子:
Dim dbBiblio As Database
Dim recPubsInNY As Recordset, strSQLStmt As String
Const DB_READONLY = 4                           ' 设置常量。
'打开数据库。
Set dbBiblio = OpenDatabase("BIBLIO.MDB")
' 为SQL 语句设置文本。
strSQLStmt = "SELECT * FROM Publishers WHERE _
        State = 'NY'"
' 创建新的记录集对象。
Set recPubsInNY = db.OpenRecordset(strSQLStmt, _
        dbReadOnly)

推荐使用的菜单前缀
应用程序频繁使用许多菜单控件,对于这些控件具备一组唯一的命名约定很实用。除了
最前面 "mnu" 标记以外,菜单控件的前缀应该被扩展:对每一级嵌套增加一个附加前缀
,将最终的菜单的标题放在名称字符串的最后。下表列出了一些例子。

菜单标题序列            菜单处理器名称

File Open               mnuFileOpen
File Send Email         mnuFileSendEmail
File Send Fax           mnuFileSendFax
Format Character        mnuFormatCharacter
Help Contents           mnuHelpContents

当使用这种命名约定时,一个特定的菜单组的所有成员一个接一个地列在 Visual Basic
的“属性”窗口中。而且,菜单控件的名字清楚地表示出它们所属的菜单项。
为其它控件选择前缀
对于上面没有列出的控件,应该用唯一的由两个或三个字符组成的前缀使它们标准化,
以保持一致性。只有当需要澄清时,才使用多于三个字符的前缀。
例如,对于派生的或修改的控件象上述那样扩展其前缀,使得在真正使用了哪一个控件
的问题上避免混淆。对于第三方控件,应该把制造商的小写缩写名附加到前缀中。例如
,从 Visual Basic Professional 3D 框架中创建的一个控件实例可以用 fra3d 这样的
前缀,以避免混淆所使用的控件。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值