日期:2010-09-12  浏览次数:20995 次

<%
'在 Class 块中,成员通过相应的声明语句被声明为 Private(私有成员,只能在类内部调用) 或 Public(公有成员,可以在类内外部调用) 。
'被声明为 Private 的将只在 Class 块内是可见的。被声明为 Public 不仅在 Class 块的内部是可见的,对 Class 块之外的代码也是可见的。
'没有使用 Private 或 Public 明确声明的被默认为 Public。在类的块内部被声明为 Public 的过程(Sub 或 Function)将成为类的方法。
'Public 变量将成为类的属性,同使用 Property Get、Property Let 和 Property Set 显式声明的属性一样。
'类的缺省属性和方法是在它们的声明部分用 Default 关键字指定的。
Class myClass
'//----声明(声明就是定义)myClass类的类内部(私有的[Private])变量
Private strAuthor
Private strVersion
Private strExample

'//---------------------------定义类的事件-------------------------------//
'//----Class_Initialize()是类的初始化事件,只要一开始使用该类,首先会触发该部分的执行.
'下面我们会在该成员中初始化该类的作者和版本以在屏幕上显示一下该类已经开始了

Private Sub Class_Initialize()
strAuthor = "思源"
strVersion = "1.0"
Response.Write "<br/>myClass开始了<br/>"
End Sub
'//----Class_Terminate()是类的结束事件,只要一退出该类,就会触发该事件.
'下面我们会该事件中设定退出该类时会在屏幕上显示该类已结束了。

Private Sub Class_Terminate()
Response.Write "<br/>myClass结束了<br/>"
End Sub

'//---------------------------用户自己定义的方法-------------------------------//

'//----该方法返回一个版本信息

Public Sub Information()
Response.Write "<br/>Coding By <a href='mailto:coder@sinobe.com'>Maxid_Zen</a> @ <a href='http://www.design60s.com'>www.design60s.com</a>.<br/>"
End Sub

'//---------------------------定义类的输出属性-------------------------------//

'//----定类的属性,该属性是让用户初始化strExample变量

Public Property Let setExample(ByVal strVar)
strExample = strVar
End Property

'//---------------------------定义类的输出属性-------------------------------//

'//----定义类的属性,该属性是返回一个版本号

Public Property Get Version
Version = strVersion
End Property

'//----定义类的属性,该属性是返回该类的作者号

Public Property Get Author
Author = strAuthor
End Property

'//----定义类的属性,该属性是返回用户自定义信息

Public Property Get Example
Example = strExample
End Property


End Class
%>
<%

'//-------这里是使用该类的例子

Dim oneNewClass

Set oneNewClass = new myClass

Response.Write "作者:" & oneNewClass.Author & "<br/>"
Response.Write "版本:" & oneNewClass.Version & "<br/>"

oneNewClass.setExample = "这是一个简单类的例子"

Response.Write "用户自定义:" & oneNewClass.Example & "<br/>"

oneNewClass.Information

Set oneNewClass = Nothing

%>

Property Get 语句
在 Class 块中,声明构成用来取得(返回)的值的属性过程的主体的名称、参数和代码。

[Public [Default]| Private] Property Get name [(arglist)]
[statements]
[[Set] name = expression]
[Exit Property]
[statements]
[[Set] name = expression]
End Property

参数
Public

表明Property Get 过程可以被所有脚本中的其他过程访问。

Default

只与 Public 关键字一起使用,表明 Property Get 过程中定义的属性为类的缺省属性。

Private

表明 Property Get 过程只对定义它的 Class 块中的其他过程是可以访问的。

name

Property Get 过程的名称;遵守标准的变量命名规则,区别仅仅在于它可以与同一Class块中的Property Let 或 Property Set过程。

arglist

该变量列表代表了 Property Get 过程被调用时传递给它的参数。多个参数之间用逗号分隔开。Property Get 过程中的每个参数的名称必须与 Property Let 过程中的相应参数相同(如果有的话)。

statements

任意的一组语句,将在 Property Get 过程的主体中执行。

Set

在将对象作为 Property Get 过程的返回值时使用的关键字。

expression

Property Get 过程的返回值。

说明
如果未使用 Public 或 Private明确声明,则 Property Get 过程被缺省为公有的,即它们对于脚本中的其他所有过程都是可见的。Property Get过程中的局部变量的值在不同的过程调用之间是不保存的。

在其他任何过程(例如 Function 或 Property Let) 内部都不能定义 Property Get 过程。

Exit Property 语句将导致立即从 Property Get 过程中退出。程序将继续执行调用 Property Get 过程的语句之后的程序。Exit Property 语句可以出现在 Property Get 过程中的任何位置,次数不限。

与Sub 和 Property Let 过程类似,Property Get 过程是能够接受参数的过程,可以执行一系列的语句,以及改变参数的值。然而,与Sub 和 Property Let 不同的是,Property Get 过程可以被用于表达式的右侧,用与使用Function 或属性名称相同的方式来返回属性的值。

Property Let