VBS 类

VBS类学习

 

Class Student  '创建一个学生类

  Public sName '创建一个公有变量 学生名称

     Private sAge '创建一个私有变量  学生年龄

 

     Public Property Let SetSName(ByVal name) '定义公有的Let属性

    sName=name

     End Property

 

   Public Property Get GetSName() '定义公有的Set属性

    GetSName=sName       'VBS是弱类型的,将sName的赋值给GetSName返回

  End Property

 

  Private Sub Class_Initalize '设置类的初始化事件

    sAge=18

  End Sub

 

  Private Sub Class_terminate '设置类的清空事件

    Response.Write("类已经注销")

  End Sub

 

  Public Function GetStudent(ByVal name) 'Function过程可以有返回值

    call SetSName(name)

    GetStudent="姓名是"&GetSName&"年龄是"&sAge '&代表字符串拼接

  End Function

 

  Public Sub OutPutStudent() 'Sub过程没有返回值,但是可以调用系统的输入函数 InputBox  消息函数 MesBox 消息函数

    name=InputBox("请输入名称")

    call SetSName(name)

    Response.Write(姓名是"&GetSName&"年龄是"&sAge )  

  End Sub 

End Class

posted @ 2010-11-23 09:46  birchlee  阅读(387)  评论(0编辑  收藏  举报