2011年计算机等考二级VB辅导知识技巧总结(5)

3、请养成以下的“对象命名约定”良好习惯
#
推荐使用的控件前缀 #
控件类型 前缀 例子 #
复选框Check box chk chkReadOnly
组合框Combo box cbo cboEnglish #
命令按钮Command button cmd cmdExit
#
通用对话框Common dialog dlg dlgFileOpen
目录列表框Directory list box dir dirSource
#
驱动器列表框Drive list box drv drvTarget
文件列表框File list box fil filSource #
窗体Form frm frmEntry #
图象框Image img imgIcon
#
标签Label lbl lblHelpMessage #
列表框List box lst lstPolicyCodes #
菜单Menu mnu mnuFileOpen
#
单选按钮Option button opt optGender
图片框Picture box pic picVGA #
文本框Text box txt txtLastName #
时钟控件Timer tmr tmrAlarm #
变量 #
声明所有的变量将会节省编程时间,因为键入操作引起的错误减少了(例如,究竟是 aUserNameTmp,还是 sUserNameTmp,还是 sUserNameTemp)。在“选项”对话框的“编辑器”标签中,复选“要求变量声明”选项。Option Explicit 语句要求在 Visual Basic 程序中声明所有的变量。
#
应该给变量加前缀来指明它们的数据类型。而且前缀可以被扩展,用来指明变量范围,特别是对大型程序。 #
用下列前缀来指明一个变量的数据类型。
变量数据类型 #
数据类型 前缀 例子 #
String (字符串类型) str strFName
#
Integer (短整数类型) int intQuantity
#
Long (长整数类型) lng lngDistance
Single (单精度浮点数类型) sng sngAverage
Double (双精度浮点数类型) dbl dblTolerance #
Boolean (布尔类型) bln blnFound #
Byte(字节类型) byt bytRasterData #
Date (日期类型) dte dteNow
Currency (货币类型) cur curRevenue
#
Object (对象类型) obj objCurrent #
Variant (变体类型) vnt vntCheckSum #