网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.在ASP中使用均速分页法提高分页速.
.Varchar与char的区别.
.教你一次下载网页中的所有资源.
.一种理论上最快的Web数据库分页方.
.在ASP中使用Oracle数据库技巧.
.用ADO的COMMAND对象实现对WEB数据.
.Connection对象的应用.
.asp实现关键词获取(各搜索引擎,g.
.不用数据源打开数据库(DSNless .
.将半角"转换为中文"的.
.构建你的网站新闻自动发布系统之.
.使用ASP和Word进行服务器端拼写检.
.使用索引服务器- 使用索引服务器.
.使用索引服务器 - 创建ASP页面.
.asp+oracle分页程序类(XDOWNPAG.
.ASP如何跳出本次进入下一次循环.
.asp中自定义文件下载.
.如何使用ASP在自己的网站建立投票.
.ASP提速技巧.
.加密处理使密码更安全[CFS编码加.

VBSctipt 5.0中的新特性

发表日期:2001-3-25


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_
                      &”     End If” & vbCrlf_
                      &”End Sub” & vbCrlf
Execute strCheckBirthday
CheckBirthday(Date())

一个回车返回(如程序中示)或冒号字符“:”可用来分隔一个字符串中的各条语句。

5、  设置地区
新的SetLocale方法可以用来改变脚本引擎的当前地区,可正确显示特殊的地区特定字符,如带重音符的字符或来自不同字符集的字符。
StrCurrentLocale = GetLocale
SetLocale(“en-gb”)

6、 正则表达式
VBScript 5.0现在支持正则表达式(过去只在JavaScript、Jscript和其他语言中可用)。RegExp对象常用来创建和执行正则表达式,例如:
StrTarget = “test testing tested attest late start”
Set objRegExp = New RegExp                              ‘create a regular expression

ObjRegExp.Pattern = “test*”                                          ‘set the search pattern
ObjRegExp.IgnoreCase = False                                   ‘set the case sensitivity
ObjRegExp.Global = True                                    ‘set the scope

Set colMatches = objRegExp.Execute(strTarget)         ‘execute the search

For Each Match in colMatches                                 ‘iterate the colMatches collection
       Response.Write “Match found at position” & Match.FirstIndex & “.”
       Resposne.Write “Matched value is ‘” & Match.Value & “’.<BR>”
Next
执行结果如下:
Match found at position 0. Matched value is ‘test’.
Match found at position 5. Matched value is ‘test’.
Match found at position 13. Matched value is ‘test’;
Match found at position 22. Matched value is ‘test’.

7、  在客户端VBScript中设置事件处理程序
这不是直接应用于ASP的脚本技术,这个新的特性在编写客户端的VBScript时是很有用的。现在可以动态指定一个函数或子程序与一个事件相关联。例如,假设一个函数的名称为MyFunction(),可把这指定给按钮的OnClick事件:
Function MyFunction()
        …
       Function implementation code here
        …
End Function

Set objCimButton = document.all(“cmdButton”)
Set objCmdButton.OnClick = GetRef(“Myfunction”)
这提供了JavaScript和Jscript中的类似功能,函数可以被动态地指定为一个对象的属性。

8、  VBScript中的On Error Goto 0
尽管这个技术早先没有被文档记载,但在现有的VBScript版本中能够使用(有着VB背景并且有好奇心的人可能早已发现这个秘密)。它现在已被记录在文档中,并且在执行On Error Resume Next后能够用来“关闭”页面中的定制错误处理。结果是任何后来的错误将引发一个浏览器级或服务器级的错误及相应的对话框/响应。

上一篇:如何在VC++ 编写的组件中使用 ADO 人气:14059
下一篇:ASP.NET中使用多个runat=server form 人气:9543
浏览全部的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐