麻烦各位大哥帮帮忙 帮我解释一下代码

来源:百度知道 编辑:UC知道 时间:2024/05/17 23:59:01
<%
class Item
dim ID,Name,ParentID,Note,WebID

Private Sub Class_Initialize
ID=0
Name=""
Note=""
WebID=0
ParentID=0
End Sub

Private Sub Class_Terminate
End Sub

Public Function setID(num)
if isNumeric(num) then
if num>0 then
ID=clng(num)
end if
end if
End Function

Public Function setWebID(num)
if isNumeric(num) then
if num>0 then
WebID=clng(num)
end if
end if
End Function

Public Function read()
dim result
result=false
dim sql,rs
set rs=server.createobject("adodb.recordset")
sql="select * from item where ID="&ID&" and (startTime is null or EndTime is Null) or ((startTime is not null and startTime<=Now()) and (endTime is not null and endTime>=Now())) and webID="&WebID
rs.open s

如果我没看错的话着段代码应该是asp里的
class Item
定义了一个类

Private Sub Class_Initialize
ID=0
Name=""
Note=""
WebID=0
ParentID=0
End Sub
该函数为构造函数,在使用 set new 创建对象时,自动执行

Private Sub Class_Terminate
End Sub
该函数为析构函数,在使用 set nothing 释放对象时,自动执行

你在下面看到的类似
Public Function setWebID(num)
……
End Function
这样的代码就是定义了这个对象的一个方法属性。
如果你对面向对象有一点了解的话应该可以看明白这段代码的是干什么用的。

你给的着段代码最后好象还少个end class
使用这个类
set obj = new Item '自动调用 class_initialize 函数
call ojb.setID(20)'id取值是20
call ojb.read()
set ojb=nothing '自动调用 class_terminate 函数

ASP 类比较简单,它不具有真正意义类的继承、重载等特性,尽管如此,它仍然是非常有用的,它降低了我们编程的复杂度,使我们的程序模块更加合理。