再發幾個ASP不錯的函數_應用技巧

來源:互聯網
上載者:User
********************
'函數作用:根據條件真假返回選定值中的某個
'參數:blnCondition:條件變數,varResultTrue:條件為真時傳回值,varResultFalse:條件為假時傳回值
Function IIF(blnCondition, varResultTrue,varResultFalse)
   If CBool(blnCondition) Then
      IIF = varResultTrue
   Else
      IIF = varResultFalse
   End If
End Function

'********************
'函數作用:判斷某個字串元素是否在給定枚舉中
'參數:sEle:待判斷的字串,sArray:指定枚舉
'舉例:根據副檔名判斷是否圖片檔案:InArray(strFileExt,"jpg,gif,bmp,png")
Function InArray(sEle,sArray)
    Dim aArray
    Dim i
    aArray = Split(sArray,",")
    For i = 0 To UBound(aArray)
        If Trim(sEle) = Trim(aArray(i)) Then
            InArray = True
            Exit Function
        End If
    Next
    InArray = False
End Function
'********************
'函數作用:判斷某個字串是否符合Regex
'參數:strString:字串,strPattern:Regex
Function doReTest(strString, strPattern)
    Dim oRE
    Set oRE = New RegExp
    oRE.Pattern = strPattern
    oRE.IgnoreCase = True
    doReTest =  oRE.Test(strString)
    Set oRE = Nothing
End Function
'********************
'函數作用:正則提取
'參數:string:字串,patrn:Regex
'返回:逗號分割的結果數組整合
Function doReExec(strng,patrn)
  Dim regEx, Match, Matches,RetStr      ' 建立變數。
  Set regEx = New RegExp         ' 建立Regex。
  regEx.Pattern = patrn          ' 設定模式。
  regEx.IgnoreCase = True         ' 設定為不區分大小寫。
  regEx.Global = True         ' 設定全域適用。
  Set Matches = regEx.Execute(strng)   ' 執行搜尋。
  For Each Match in Matches      ' 對 Matches 集合進行迭代。
    RetStr = RetStr & Match.Value & "," & vbCRLF
  Next
  doReExec = RetStr
End Function
複製代碼 '********************
'函數作用:顯示分頁連結
'參數:lngCurPage:當前頁是第幾頁,lngPageCount:一共幾頁,strSueryString:分頁連結需要附加的QueryString變數
Sub showPageNav(lngCurPage,lngPageCount,ByVal strQueryString)
    Response.Write "當前第" & lngCurPage & "頁,共:" & lngPageCount & "頁"
    Dim i,j,k
    If lngCurPage = 1 Then                    '如果是第一頁
        '如果lngPageCount小於10,則導航頁最多到lngPageCount頁
        If lngPageCount < 10 Then
            j = lngPageCount
        Else
            j = 10
        End If
        For i = 2 To j
            Response.Write("<a href=""?" & strQueryString & "&p=" & i & """>" & i & "</a> ")
        Next
    ElseIf lngCurPage = lngPageCount Then    '如果是最後一頁
        '如果lngPageCount小於10,則導航起始從1開始
        If lngPageCount < 10 Then
            j = 1
        Else
            j = lngPageCount - 10
        End If
        For i = j To lngPageCount - 1
            Response.Write("<a href=""?" & strQueryString & "&p=" & i & """>" & i & "</a> ")
        Next
        Response.Write(lPageCount)
    Else                                    '如果是中間的頁
        If lngCurPage <= 5 Then
            j = 1
        Else
            j = lngCurPage - 5
        End If
        If lngPageCount <= lngCurPage + 5 Then
            k = lngPageCount
        Else
            k = lngCurPage + 5
        End If
        Response.Write("<a href=""?" & strQueryString & "&p=" & 1 & """>" & "<<" & "</a>  ")
        For i = j To lngCurPage - 1
            Response.Write("<a href=""?" & strQueryString & "&p=" & i & """>" & i & "</a> ")
        Next
        Response.Write(lngCurPage & " ")
        For i = lngCurPage + 1 To k
            Response.Write("<a href=""?" & strQueryString & "&p=" & i & """>" & i & "</a> ")
        Next
        Response.Write(" <a href=""?" & strQueryString & "&p=" & lPageCount & """>" & ">>" & "</a>")
    End If    
End Sub
'********************
'函數作用:當前頁請求方式是否為POST
'說明:用於在同一頁面處理顯示和資料操作,當PostBack()為真時說明提交表單至當前頁,應進行資料後台操作
Function PostBack()
    If UCase(Trim(Request.ServerVariables("REQUEST_METHOD"))) = "POST" Then
        PostBack = True
    Else
        PostBack = False
    End If
End Function
'********************
'函數作用:返回執行長度的隨機字串
'參數:Length:長度
Function GenRadomString(Length) 
    dim i, tempS, v 
    dim c(39) 
    tempS = "" 
    c(1) = "a": c(2) = "b": c(3) = "c": c(4) = "d": c(5) = "e": c(6) = "f": c(7) = "g" 
    c(8) = "h": c(9) = "i": c(10) = "j": c(11) = "k": c(12) = "l": c(13) = "m": c(14) = "n" 
    c(15) = "o": c(16) = "p": c(17) = "q": c(18) = "r": c(19) = "s": c(20) = "t": c(21) = "u" 
    c(22) = "v": c(23) = "w": c(24) = "x": c(25) = "y": c(26) = "z": c(27) = "1": c(28) = "2" 
    c(29) = "3": c(30) = "4": c(31) = "5": c(32) = "6": c(33) = "7": c(34) = "8": c(35) = "9" 
    If isNumeric(Length) = False Then 
        Response.Write "A numeric datatype was not submitted to this function." 
        Exit Function 
    End If 
    For i = 1 to Length 
        Randomize 
        v = Int((35 * Rnd) + 1) 
        tempS = tempS & c(v) 
    Next 
    GenRadomString = tempS 
End Function

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.