当前位置: 首页 > 图文教程 > 网络编程 > ASP > VBSctipt 5.0中的新特性

ASP
asp使用activex组件实例一
ASP中检查没有数据提交的页面Ⅰ
ASP中检查没有数据提交的页面Ⅱ
为ASP开发者介绍ColdFusion
W3 Jmail 简要介绍
W3 Jmail 参考说明
W3 Jmail 使用范例
ASP教程:堵住ASP漏洞
利 用 ASP 开 发 网 络 聊 天 室
MySQL数据库基础教程
ASP和SQLServer时间处理方法Ⅰ
如何利用ASP实现邮箱访问
SQL语言快速入门之一
SQL语言快速入门之二
SQL语言快速入门之三(一)
用纯ASP代码实现图片上传并存入数据库中
ASP进阶教程Ⅹ:留言簿自动发E-Mail
单元测试和事先测试开发(2)
.NET的事务控制.
.NET 的数据访问应用程序块(Data Access Application Block)

ASP 中的 VBSctipt 5.0中的新特性


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 68 ::
收藏到网摘: n/a

  VBSctipt 5.0中的新特性

能够在ASP中应用的特性包括了那些由脚本引擎所提供的特性,这意味着VBScript的改进也可在ASP中应用。VBScript的改进如下所述:

1、 在脚本中使用类
在VBScript中实现完整的VB类(class)模型,但明显的例外是在ASP服务器端的脚本事件。可以在脚本中创建类,使它们的属性和方法能够和用于页面的其余代码,例如:
Class MyClass

        Private m_HalfValue                                ‘Local variable to hold value of HalfValue

Public Property Let HalfValue(vData)             ‘executed to set the HalfValue property
              If vData > 0 Then m_HalfValue = vData
End Property

Public Property Get HalfValue()                     ‘executed to return the HalfValue property
              HalfValue = m_HalfValue
End Property

Public Function GetResult()                            ‘implements the GetResult method
              GetResult = m_HalfVaue * 2
End Function
End Class

Set ObjThis = New MyClass

ObjThis.HalfValue = 21

Response.Write “Value of HalfValue property is “ & objThis.HalfValue & “<BR>”
Response.Write “Result of GetResult method is “ & objThis.GetResult & “<BR>”

这段代码产生如下结果:
Value of HalfValue property is 21
Result of GetResult method is 42

2、 With结构
VBScript 5.0支持With结构,使访问一个对象的几个属性或方法的代码更加紧凑:

Set objThis = Server.CreateObject(“This.object”)

With objThis
.Property1 = “This value”
.Property2 = “Another value”
TheResult = .SomeMethod
End With


3、 字符串求值
Eval函数(过去只在JavaScript和Jscript中可用)目前在VBScript 5.0中已经得到了支持。允许创建包含脚本代码的字符串,值可为True或False,并在执行后可得到一个结果:

datYourBirthday = Request.Form(“Birthday”)
strScript = “datYourBirthday = Date()”

If Eval(strScript) Then
       Response.write “Happy Brithday!”
Else
       Response.write “Have a nice day!”
End If


4、 语句执行
新的Execute函数允许执行一个字符串中的脚本代码,执行方式与Eval函数相同,但是不返回结果。它可以用来动态创建代码中稍后执行的过程,例如:

strCheckBirthday = “Sub CheckBirthday(datYourBirthday)” & vbCrlf_
                      & “   If  Eval(datYourBirthday = Date()) Then” & vbCrlf_
                      & “                Response.Write “”Happy Birthday!””” & vbCrlf_
                      &”     Else” & vbCrlf_
                      &”                 Response.write “”Have a nice day!””” & vbCrlf_