在 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
%>
请稍等,评论加载中...