• <label id="pxtpz"><meter id="pxtpz"></meter></label>
      1. <span id="pxtpz"><optgroup id="pxtpz"></optgroup></span>

        當前位置:雨林木風下載站 > 技術開發教程 > 詳細頁面

        VBSctipt 5.0中的新特征

        VBSctipt 5.0中的新特征

        更新時間:2022-05-13 文章作者:未知 信息來源:網絡 閱讀次數:

        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時是很有用的,F在可以動態指定一個函數或子程序與一個事件相關聯。例如,假設一個函數的名稱為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后能夠用來“關閉”頁面中的定制錯誤處理。結果是任何后來的錯誤將引發一個瀏覽器級或服務器級的錯誤及相應的對話框/響應。

        溫馨提示:喜歡本站的話,請收藏一下本站!

        本類教程下載

        系統下載排行

        主站蜘蛛池模板: 亚洲午夜电影在线观看高清| 国产自偷亚洲精品页65页| 亚洲综合久久成人69| 无码AV片在线观看免费| 亚洲视频在线视频| 91精品国产免费久久国语麻豆| 亚洲av无码一区二区三区网站| 亚洲精品免费观看| 亚洲日韩乱码中文无码蜜桃| 四虎精品视频在线永久免费观看| 久久精品国产亚洲av麻豆蜜芽| 日韩欧美一区二区三区免费观看 | 青青草原1769久久免费播放| 国产午夜亚洲精品理论片不卡| 中文字幕无线码中文字幕免费| 亚洲av无码成h人动漫无遮挡| 免费国产黄网站在线观看可以下载| 亚洲精品免费在线视频| 免费人成在线视频| 美女免费视频一区二区| 亚洲午夜久久久久久噜噜噜| 99re6在线精品视频免费播放| 亚洲综合国产成人丁香五月激情| 日本免费一区二区三区最新 | 亚洲精品动漫免费二区| 337P日本欧洲亚洲大胆艺术图 | 97在线观免费视频观看| 小说专区亚洲春色校园| 亚洲精品国产品国语在线| 最近中文字幕完整免费视频ww | 中文字幕乱码一区二区免费| 精品日韩99亚洲的在线发布| 亚洲AV无码乱码在线观看牲色| 在线涩涩免费观看国产精品| 中国亚洲呦女专区| 亚洲精品无码MV在线观看| 成人免费午夜无码视频| 成人免费一区二区三区| 亚洲人成网国产最新在线| 亚洲人成色7777在线观看不卡| 8x8×在线永久免费视频|