1在ASP中使用类(Class)在ASP中使用类(class)
  2在ASP中使用类(Class)在不入前的一天,当我为了解决一个语法问题来翻阅VBscript文档时,偶然间发现在了下面的一句话:
  3在ASP中使用类(Class)
  4在ASP中使用类(Class)Class Statement
  5在ASP中使用类(Class)
  6在ASP中使用类(Class)Declares the name of a class, as well as a definition of the variables, properties, and methods that comprise the class. 
  7在ASP中使用类(Class)
  8在ASP中使用类(Class)翻译过来就是在ASP中使用类(Class)在ASP中使用类(Class)
  9在ASP中使用类(Class)
 10在ASP中使用类(Class)Class 声明
 11在ASP中使用类(Class)
 12在ASP中使用类(Class)声明一个类的名字,就是定义一些变量,属性,方法来组成一个类 
 13在ASP中使用类(Class)
 14在ASP中使用类(Class)这是真的!!!?VBScript中能用类!?!?不知道能不能用于ASP!?这样的话,我就不是能写出像object一样的ASP程序?!说干就干!实践是检验真理的唯一标准,自个动手吧!
 15在ASP中使用类(Class)
 16在ASP中使用类(Class)我们常常看到别的程序语言中中都有类的说明,PHP,VB,C++,这个在VBScript中的类的说明,我是第一次听到,我们的日常工作就是网站开发,在这个里面多多少少搞出点经验,像模像样也能自诩为"内行",所以我就来分享一下我所知道的这个新的东东。我们来看看下面的这个代码吧!(window2000+IIS5.0通过测试)
 17在ASP中使用类(Class)
 18在ASP中使用类(Class)<%
 19在ASP中使用类(Class)''声明一个名为aspcn的类 
 20在ASP中使用类(Class)Class aspcn
 21在ASP中使用类(Class)Private aspcn
 22在ASP中使用类(Class)''初始化类
 23在ASP中使用类(Class)Private Sub Class_Initialize
 24在ASP中使用类(Class)aspcn="Aspcn Is Good!<br>"
 25在ASP中使用类(Class)End Sub
 26在ASP中使用类(Class)''定义一个函数
 27在ASP中使用类(Class)Public Function DoIt()
 28在ASP中使用类(Class)DoIt=aspcn
 29在ASP中使用类(Class)End Function
 30在ASP中使用类(Class)''定义一个方法
 31在ASP中使用类(Class)Public Sub QueryStr(stat)
 32在ASP中使用类(Class)Response.write stat
 33在ASP中使用类(Class)End Sub 
 34在ASP中使用类(Class)
 35在ASP中使用类(Class)End Class
 36在ASP中使用类(Class)
 37在ASP中使用类(Class)Set Hi_aspcn=New aspcn ''定义一个名为Hi_aspcn的aspcn对象实例
 38在ASP中使用类(Class)response.write Hi_aspcn.DoIt
 39在ASP中使用类(Class)varstr="Aspcn Is Cool!<br><font color=red>http://www.aspcn.com</font><br>WelCome!!!"
 40在ASP中使用类(Class)Hi_aspcn.QueryStr varstr 
 41在ASP中使用类(Class)
 42在ASP中使用类(Class)%>
 43在ASP中使用类(Class)
 44在ASP中使用类(Class)
 45在ASP中使用类(Class)这是很简单的一个程序,我们在其中声明了一个名为aspcn的类,建立了一个DoIt函数,一个QueryStr方法,这个程序很简单相信大家能看懂,它的显示如下: 
 46在ASP中使用类(Class)
 47在ASP中使用类(Class)Aspcn Is Good!
 48在ASP中使用类(Class)Aspcn Is Cool!
 49在ASP中使用类(Class)http://www.aspcn.com/
 50在ASP中使用类(Class)WelCome!!! 
 51在ASP中使用类(Class)
 52在ASP中使用类(Class)以后,咱们就可以把我们常用到的程序写成一个类,到时候就用<--#include file="xxx.asp"-->来包含进来就行了,这给我们开发程序又提供了新的空间,真是爽啊!和C++一样了,有点回归自然的感觉. 
 53在ASP中使用类(Class)
 54在ASP中使用类(Class)
 55在ASP中使用类(Class)     VBSctipt 5.0中的新特性 
 56在ASP中使用类(Class)
 57在ASP中使用类(Class)能够在ASP中应用的特性包括了那些由脚本引擎所提供的特性,这意味着VBScript的改进也可在ASP中应用。VBScript的改进如下所述:
 58在ASP中使用类(Class)
 59在ASP中使用类(Class)1、 在脚本中使用类
 60在ASP中使用类(Class)在VBScript中实现完整的VB类(class)模型,但明显的例外是在ASP服务器端的脚本事件。可以在脚本中创建类,使它们的属性和方法能够和用于页面的其余代码,例如:
 61在ASP中使用类(Class)Class MyClass
 62在ASP中使用类(Class)
 63在ASP中使用类(Class)Private m_HalfValue ‘Local variable to hold value of HalfValue
 64在ASP中使用类(Class)
 65在ASP中使用类(Class)Public Property Let HalfValue(vData) ‘executed to set the HalfValue property
 66在ASP中使用类(Class)If vData > 0 Then m_HalfValue = vData
 67在ASP中使用类(Class)End Property
 68在ASP中使用类(Class)
 69在ASP中使用类(Class)Public Property Get HalfValue() ‘executed to return the HalfValue property
 70在ASP中使用类(Class)HalfValue = m_HalfValue
 71在ASP中使用类(Class)End Property
 72在ASP中使用类(Class)
 73在ASP中使用类(Class)Public Function GetResult() ‘implements the GetResult method
 74在ASP中使用类(Class)GetResult = m_HalfVaue * 2
 75在ASP中使用类(Class)End Function
 76在ASP中使用类(Class)End Class
 77在ASP中使用类(Class)
 78在ASP中使用类(Class)Set ObjThis = New MyClass
 79在ASP中使用类(Class)
 80在ASP中使用类(Class)ObjThis.HalfValue = 21
 81在ASP中使用类(Class)
 82在ASP中使用类(Class)Response.Write “Value of HalfValue property is “ & objThis.HalfValue & “<BR>
 83在ASP中使用类(Class)Response.Write “Result of GetResult method is “ & objThis.GetResult & “<BR>
 84在ASP中使用类(Class)
 85在ASP中使用类(Class)这段代码产生如下结果:
 86在ASP中使用类(Class)Value of HalfValue property is 21
 87在ASP中使用类(Class)Result of GetResult method is 42
 88在ASP中使用类(Class)
 89在ASP中使用类(Class)2、 With结构
 90在ASP中使用类(Class)VBScript 5.0支持With结构,使访问一个对象的几个属性或方法的代码更加紧凑:
 91在ASP中使用类(Class)
 92在ASP中使用类(Class)Set objThis = Server.CreateObject(“This.object”)
 93在ASP中使用类(Class)
 94在ASP中使用类(Class)With objThis
 95在ASP中使用类(Class).Property1 = “This value”
 96在ASP中使用类(Class).Property2 = “Another value”
 97在ASP中使用类(Class)TheResult = .SomeMethod
 98在ASP中使用类(Class)End With
 99在ASP中使用类(Class)
100在ASP中使用类(Class)
101在ASP中使用类(Class)3、 字符串求值
102在ASP中使用类(Class)Eval函数(过去只在JavaScript和Jscript中可用)目前在VBScript 5.0中已经得到了支持。允许创建包含脚本代码的字符串,值可为True或False,并在执行后可得到一个结果:
103在ASP中使用类(Class)
104在ASP中使用类(Class)datYourBirthday = Request.Form(“Birthday”)
105在ASP中使用类(Class)strScript = “datYourBirthday = Date()”
106在ASP中使用类(Class)
107在ASP中使用类(Class)If Eval(strScript) Then
108在ASP中使用类(Class)Response.write “Happy Brithday!”
109在ASP中使用类(Class)Else
110在ASP中使用类(Class)Response.write “Have a nice day!”
111在ASP中使用类(Class)End If
112在ASP中使用类(Class)
113在ASP中使用类(Class)
114在ASP中使用类(Class)4、 语句执行
115在ASP中使用类(Class)新的Execute函数允许执行一个字符串中的脚本代码,执行方式与Eval函数相同,但是不返回结果。它可以用来动态创建代码中稍后执行的过程,例如:
116在ASP中使用类(Class)
117在ASP中使用类(Class)strCheckBirthday = “Sub CheckBirthday(datYourBirthday)” & vbCrlf_
118在ASP中使用类(Class)& “ If Eval(datYourBirthday = Date()) Then” & vbCrlf_
119在ASP中使用类(Class)& “ Response.Write “”Happy Birthday!””” & vbCrlf_
120在ASP中使用类(Class)&” Else” & vbCrlf_
121在ASP中使用类(Class)&” Response.write “”Have a nice day!””” & vbCrlf_
122在ASP中使用类(Class)&” End If” & vbCrlf_
123在ASP中使用类(Class)&End Sub” & vbCrlf
124在ASP中使用类(Class)Execute strCheckBirthday
125在ASP中使用类(Class)CheckBirthday(Date())
126在ASP中使用类(Class)
127在ASP中使用类(Class)一个回车返回(如程序中示)或冒号字符“:”可用来分隔一个字符串中的各条语句。
128在ASP中使用类(Class)
129在ASP中使用类(Class)5、 设置地区
130在ASP中使用类(Class)新的SetLocale方法可以用来改变脚本引擎的当前地区,可正确显示特殊的地区特定字符,如带重音符的字符或来自不同字符集的字符。
131在ASP中使用类(Class)StrCurrentLocale = GetLocale
132在ASP中使用类(Class)SetLocale(“en-gb”)
133在ASP中使用类(Class)
134在ASP中使用类(Class)6、 正则表达式
135在ASP中使用类(Class)VBScript 5.0现在支持正则表达式(过去只在JavaScript、Jscript和其他语言中可用)。RegExp对象常用来创建和执行正则表达式,例如:
136在ASP中使用类(Class)StrTarget = “test testing tested attest late start”
137在ASP中使用类(Class)Set objRegExp = New RegExp ‘create a regular expression
138在ASP中使用类(Class)
139在ASP中使用类(Class)ObjRegExp.Pattern = “test*” ‘set the search pattern
140在ASP中使用类(Class)ObjRegExp.IgnoreCase = False ‘set the case sensitivity
141在ASP中使用类(Class)ObjRegExp.Global = True ‘set the scope
142在ASP中使用类(Class)
143在ASP中使用类(Class)Set colMatches = objRegExp.Execute(strTarget) ‘execute the search
144在ASP中使用类(Class)
145在ASP中使用类(Class)For Each Match in colMatches ‘iterate the colMatches collection
146在ASP中使用类(Class)Response.Write “Match found at position” & Match.FirstIndex & “.”
147在ASP中使用类(Class)Resposne.Write “Matched value is ‘” & Match.Value & “’.<BR>
148在ASP中使用类(Class)Next
149在ASP中使用类(Class)执行结果如下:
150在ASP中使用类(Class)Match found at position 0. Matched value is ‘test’.
151在ASP中使用类(Class)Match found at position 5. Matched value is ‘test’.
152在ASP中使用类(Class)Match found at position 13. Matched value is ‘test’;
153在ASP中使用类(Class)Match found at position 22. Matched value is ‘test’.
154在ASP中使用类(Class)
155在ASP中使用类(Class)7、 在客户端VBScript中设置事件处理程序
156在ASP中使用类(Class)这不是直接应用于ASP的脚本技术,这个新的特性在编写客户端的VBScript时是很有用的。现在可以动态指定一个函数或子程序与一个事件相关联。例如,假设一个函数的名称为MyFunction(),可把这指定给按钮的OnClick事件:
157在ASP中使用类(Class)Function MyFunction()
158在ASP中使用类(Class)
159在ASP中使用类(Class)Function implementation code here
160在ASP中使用类(Class)
161在ASP中使用类(Class)End Function
162在ASP中使用类(Class)
163在ASP中使用类(Class)Set objCimButton = document.all(“cmdButton”)
164在ASP中使用类(Class)Set objCmdButton.OnClick = GetRef(“Myfunction”)
165在ASP中使用类(Class)这提供了JavaScript和Jscript中的类似功能,函数可以被动态地指定为一个对象的属性。
166在ASP中使用类(Class)
167在ASP中使用类(Class)8、 VBScript中的On Error Goto 0
168在ASP中使用类(Class)尽管这个技术早先没有被文档记载,但在现有的VBScript版本中能够使用(有着VB背景并且有好奇心的人可能早已发现这个秘密)。它现在已被记录在文档中,并且在执行On Error Resume Next后能够用来“关闭”页面中的定制错误处理。结果是任何后来的错误将引发一个浏览器级或服务器级的错误及相应的对话框/响应。

相关文章: