日本国产亚洲-日本国产一区-日本国产一区二区三区-日本韩国欧美一区-日本韩国欧美在线-日本韩国欧美在线观看

當(dāng)前位置:雨林木風(fēng)下載站 > 技術(shù)開發(fā)教程 > 詳細(xì)頁面

VBSctipt 5.0中的新特征

VBSctipt 5.0中的新特征

更新時(shí)間:2022-05-13 文章作者:未知 信息來源:網(wǎng)絡(luò) 閱讀次數(shù):

VBSctipt 5.0中的新特性

能夠在ASP中應(yīng)用的特性包括了那些由腳本引擎所提供的特性,這意味著VBScript的改進(jìn)也可在ASP中應(yīng)用。VBScript的改進(jìn)如下所述:

1、 在腳本中使用類
在VBScript中實(shí)現(xiàn)完整的VB類(class)模型,但明顯的例外是在ASP服務(wù)器端的腳本事件。可以在腳本中創(chuàng)建類,使它們的屬性和方法能夠和用于頁面的其余代碼,例如:
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>”

這段代碼產(chǎn)生如下結(jié)果:
Value of HalfValue property is 21
Result of GetResult method is 42

2、 With結(jié)構(gòu)
VBScript 5.0支持With結(jié)構(gòu),使訪問一個(gè)對(duì)象的幾個(gè)屬性或方法的代碼更加緊湊:

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

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


3、 字符串求值
Eval函數(shù)(過去只在JavaScript和Jscript中可用)目前在VBScript 5.0中已經(jīng)得到了支持。允許創(chuàng)建包含腳本代碼的字符串,值可為True或False,并在執(zhí)行后可得到一個(gè)結(jié)果:

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、 語句執(zhí)行
新的Execute函數(shù)允許執(zhí)行一個(gè)字符串中的腳本代碼,執(zhí)行方式與Eval函數(shù)相同,但是不返回結(jié)果。它可以用來動(dòng)態(tài)創(chuàng)建代碼中稍后執(zhí)行的過程,例如:

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())

一個(gè)回車返回(如程序中示)或冒號(hào)字符“:”可用來分隔一個(gè)字符串中的各條語句。

5、  設(shè)置地區(qū)
新的SetLocale方法可以用來改變腳本引擎的當(dāng)前地區(qū),可正確顯示特殊的地區(qū)特定字符,如帶重音符的字符或來自不同字符集的字符。
StrCurrentLocale = GetLocale
SetLocale(“en-gb”)

6、 正則表達(dá)式
VBScript 5.0現(xiàn)在支持正則表達(dá)式(過去只在JavaScript、Jscript和其他語言中可用)。RegExp對(duì)象常用來創(chuàng)建和執(zhí)行正則表達(dá)式,例如:
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
執(zhí)行結(jié)果如下:
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中設(shè)置事件處理程序
這不是直接應(yīng)用于ASP的腳本技術(shù),這個(gè)新的特性在編寫客戶端的VBScript時(shí)是很有用的。現(xiàn)在可以動(dòng)態(tài)指定一個(gè)函數(shù)或子程序與一個(gè)事件相關(guān)聯(lián)。例如,假設(shè)一個(gè)函數(shù)的名稱為MyFunction(),可把這指定給按鈕的OnClick事件:
Function MyFunction()
        …
       Function implementation code here
        …
End Function

Set objCimButton = document.all(“cmdButton”)
Set objCmdButton.OnClick = GetRef(“Myfunction”)
這提供了JavaScript和Jscript中的類似功能,函數(shù)可以被動(dòng)態(tài)地指定為一個(gè)對(duì)象的屬性。

8、  VBScript中的On Error Goto 0
盡管這個(gè)技術(shù)早先沒有被文檔記載,但在現(xiàn)有的VBScript版本中能夠使用(有著VB背景并且有好奇心的人可能早已發(fā)現(xiàn)這個(gè)秘密)。它現(xiàn)在已被記錄在文檔中,并且在執(zhí)行On Error Resume Next后能夠用來“關(guān)閉”頁面中的定制錯(cuò)誤處理。結(jié)果是任何后來的錯(cuò)誤將引發(fā)一個(gè)瀏覽器級(jí)或服務(wù)器級(jí)的錯(cuò)誤及相應(yīng)的對(duì)話框/響應(yīng)。

溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!

本類教程下載

系統(tǒng)下載排行

主站蜘蛛池模板: 成人小视频免费在线观看 | 99婷婷久久精品国产一区二区 | 91se在线看片国产免费观看 | 中文字幕亚洲精品卡通动漫 | 国产三级观看 | 草草第一页 | 四虎网址在线 | 中文日韩字幕一区在线观看 | 国产精品拍拍拍福利在线观看 | 深夜福利国产精品亚洲尤物 | 欧美一区a | 日韩经典欧美精品一区 | 国产高清在线91福利 | 欧美日韩一区二区综合在线视频 | 亚洲国产综合精品中文字幕 | 天天综合干 | 成年免费大片黄在线观看免费 | 91社区视频在线观看 | 成年人网站免费 | 天堂资源中文在线 | 国产又粗又爽又大又长免费视 | 国内精品一区二区三区αv 国内精品一区二区三区最新 | 国产午夜影院 | 极品美女久久久久久久久久久 | 夜夜操影院| 久久视频这里有精品68 | 久久综久久美利坚合众国 | 欧美久久精品一级c片片 | 久久久久99精品成人片三人毛片 | 久久久亚洲欧洲国产 | 亚洲综合一区二区不卡 | 99国产精品免费视频观看 | 亚洲精品网站日本xxxxxxx | 中文字幕日本在线观看 | 久久久久久岛国免费网站 | 久久精品国产免费高清 | 日本免费特黄aa毛片 | 在线婷婷| 久视频在线观看久视频 | 中文字幕2020 | 久久久久久久国产精品毛片 |