网络编程
位置:首页>> 网络编程>> Asp编程>> 在ASP中如何使用类class

在ASP中如何使用类class

 来源:aspcn 发布时间:2007-09-16 17:17:00 

标签:类,class,ASP

 在不久前的一天,当我为了解决一个语法问题来翻阅VBscript文档时,偶然间发现在了下面的一句话: 


  Class Statement  
    
  Declares the name of a class, as well as a definition of the variables, properties, and methods that comprise the class. 


翻译过来就是......

Class 声明 

声明一个类的名字,就是定义一些变量,属性,方法来组成一个类

这是真的!!!?VBScript中能用类!?!?不知道能不能用于ASP!?这样的话,我就不是能写出像object一样的ASP程序?!说干就干!实践是检验真理的唯一标准,自个动手吧!

我们常常看到别的程序语言中中都有类的说明,PHP,VB,C++,这个在VBScript中的类的说明,我是第一次听到,我们的日常工作就是网站开发,在这个里面多多少少搞出点经验,像模像样也能自诩为"内行",所以我就来分享一下我所知道的这个新的东东。我们来看看下面的这个代码吧!(window2000+IIS5.0通过测试)


 <%  
  ’’声明一个名为aspxhome的类  
  Class aspxhome  
  Private aspxhome  
  ’’初始化类  
  Private Sub Class_Initialize  
  aspxhome="aspxhome Is Good!<br>"  
  End Sub  
  ’’定义一个函数  
  Public Function DoIt()  
  DoIt=aspxhome  
  End Function  
  ’’定义一个方法  
  Public Sub QueryStr(stat)  
  Response.write stat  
  End Sub  
    
  End Class  
    
  Set Hi_aspxhome=New aspxhome ’’定义一个名为Hi_aspxhome的aspxhome对象实例  
  response.write Hi_aspxhome.DoIt  
  varstr="aspxhome Is Cool!<br><font color=red>http://www.aspxhome.com</font><br>WelCome!!!"  
  Hi_aspxhome.QueryStr varstr  
    
  %> 


这是很简单的一个程序,我们在其中声明了一个名为aspxhome的类,建立了一个DoIt函数,一个QueryStr方法,这个程序很简单相信大家能看懂,它的显示如下: 


  Aspxhome Is Good! 
  Aspxhome Is Cool! 
  http://www.aspxhome.com 
  WelCome!!! 


   以后,咱们就可以把我们常用到的程序写成一个类,到时候就用<!--#include file="xxx.asp"-->来包含进来就行了,这给我们开发程序又提供了新的空间,真是爽啊!和C++一样了,有点回归自然的感觉.

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com