vbs类的使用方法
vbs类的使用方法
类的结构:
class 类名称
end class
调用方法 set myclass=new 类名称
中间类里面的代码,
类模块的事件过程。
Private Sub Class_Initialize()
这里写上类实例化的时候执行的代码。
end sub
Private Sub class_terminate()
这里是类注销的时候自动执行的代码,
end Sub
上面两个子程序的名称是规定的,
如果改了名称,就会无效。
1、变量
2、函数(Function)
3、属性(Property)
4、方法 (SUB)
一、对象的访问限制,分为公有和私有,公有的(public)可以让外部访问,私有的(Private )外部不能访问,
上面几种角色都可以定义为公有或私有。
定义变量
public mystr,mystring
这样就定义了两个公有的变量,调用方法myclass.mystr
反之
Private mystr,mystring
则为私有的变量,外部不能访问的。
函数
Public Function Checkstr(Str)
If Isnull(Str) Then
CheckStr = ""
Exit Function
End If
CheckStr = Replace(Str,"'","''")
End Function
这是一个公有函数,外部可以访问的,调用方法 myclass.Checkstr(Str)
反之如果为私有的,则用Private 取代public
3、属性(Property)
属性分两种,一种是只写属性,一种是只读属性。
也可以为公有或私有,现在以公有为例子。
这是一个只写的属性
Public Property Let Value(ByVal vNewValue)
Dim tmpstr
tmpstr = vNewValue
tmpstr = split(tmpstr,"@@@")
html = split(tmpstr(0),"|||")
Strings = split(tmpstr(1),"|||")
pic = split(tmpstr(2),"|||")
End Property
这是一个只读的属性
Public Property Get TodayNum
TodayNum = Application(Forum_sn & "_Dv_setup")(9,0)
End Property