日期:2012-10-23  浏览次数:20611 次

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 (value