4.2 变量和常数 命名规范
array arr arrShoppingList
Boolean bln blnIsPostBack
Byte byt bytpixelValue
Char chr chrDelimiter
DateTime dtm dtmStartDate
Decimal dec decAverageHeight
Double dbl dblSizeOfUniverse
Interger int intRowCounter
Long lng
Object obj
Short shr
Single sng
String str
4.3 函数过程命名规范
4.3.1 统一的单词顺序: : 动词 + 名次
4.3.2 单词的首个字母大写 并且名称应该能表达出它们的用途(或者说是意义)。
4.3.3 参数需要指明 ByVal 还是 ByRef (参数是按值传递还是按地址传递)
4.4 类命名规范
i. 以 Class 声明的类,都必须以名词或名词短语命名,体现类的作用
ii. 当类是一个特性( Attribute )时,以 Attribute 结尾,当类是一个异常( Exception )时,以 Exception 结尾:
Class ColorSetException
Class CauseExceptionAttribute
iii. 当类只需有一个对象实例(全局对象,比如 Application 等),必须以 Class 结尾,如
Class ScreenClass
Class SystemClass
iv. 当类只用于作为其他类的基类,根据情况,以 Base 结尾:
MustInherit Class IndicatorBase
v. 如果定义的类是一个窗体,那么名字的后面必须加后缀 Form ,如果是 Web 窗体,必须加后缀 Page :
Class PrintForm : Inherits Form '* Windows 窗体
Class StartPage : Inherits Page '* Web 窗体
vi. 模块不是类型,他的名称除了必须以名词命名外,必须加以后缀 Module
:Module SharedFunctionsModule
五 设计规范:
5.1 对象取值赋给变量或者控件时需要判断对象是否为 nothing 例:
If not Customer is Nothing Then
Else
' Missing customer data is handled by the account and logon pages
End If
5.2 在使用dataset 对象时 用有意义的常量代替无意义的值 例:
正确的: With Customer.Tables(CustomerData.CUSTOMERS_TABLE).Rows(0)
TxtEmail.Text = CStr (.Item(CustomerData.EMAIL_FIELD))
End With
错误的: With Customer.Tables(0).Rows(0)
TxtEmail.Text = CStr (.Item(0))
TxtEmail.Text = CStr (.Item( “ Email ” ))
End With
5.3 取文本框数值的时候需要去除多余的空格例:
tmpPassword = CountryTextBox.Text.Trim()
5.4 两层嵌套以上的 if else end if 考虑使用 select case 语句 例:
错误的: if DataGrid1.Items(i).Cells(4).Text = "0" Then
ElseIf DataGrid1.Items(i).Cells(4).Text = "1" Then
ElseIf DataGrid1.Items(i).Cells(4).Text = "2" Then
DataGrid1.Items(i).Cells(4).Text = "已培训"
End If
正确的: select Case DataGrid1.Items(i).Cells(4).Text
case “ 1 ”
case “ 2 ”
case “ 3 ”
case Else
end select
5.5 Insert 语句的正确格式:Insert [into] TableName (FieldName1,FieldName2),values( value1,value2)
错误的格式: Insert [into] TableName Values (value1, value2)
方便表的扩充
** ** 5 . 6 所有的操作要有快捷键 , 支持键盘操作
5.7 用 do……loop 循环代替 while…… end while 循环
5.8 不要用 boolean 表达式与 ture 或 false 比较
不正确的用法: isEmptyRecordset= (rs.eof= ture) and( rst.eof=tuue)
正确的用法: isEmptyRecordset= rs.eof and rst.eof
if not (blnValidTemplate). Then
5.9 即使表达式不需要圆括号,为了逻辑清晰也要加上圆括号
5.10 使用统一和直接明了的方式调用过程
调用 sub 过程要使用 call 关键字(区别于没有返回值的函数调用)
不正确的用法 performWordMerge(strMergeFile)
正确的用法: call performWordMerge(strMergeFile)
5.11 即使没有返回值的函数也要始终接受函数的返回值
5.12 使用 return 返回函数值
不正确地用法: priavire function myFunction () as Boolean
myFunction =true
end sub
正确地用法: priavire function myFunction () as Boolean
return true
end sub
5.13 常量的编程规则
所有的常量前面加上前缀 C_ 和范围指示符
例如:过程中 const c_InterestRate=6
模块中( private ) private Const mc_IntersRate=6
全局: public Const gc_intersRate=5
5.14 决不要用 + 做字符串的连接符,要使用 & 符号
5.15 用空白行把相关的语句分组
在 if …..then ,select case 结构 每个循环体 的前后插入空白行
在声明一组变量后,执行同一任务的语句组之后插入空白行
过程之间插入两个空白行
5.16 给每个过程定义一个明确的范围
不正确地用法: sub disp;lay confiirmationmessage
end sub
正确地用法: public sub disp;lay confiirmationmessage
end sub
……………………. <SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-ha