********************
'函數作用:根據條件真假返回選定值中的某個
'參數: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
'********************
'函數作用:判斷某個字符串是否符合正則表達式
'參數:strString:字符串,strPattern:正則表達式
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:正則表達式
'返回:逗號分割的結果數組集成
Function doReExec(strng,patrn)
Dim regEx, Match, Matches,RetStr ' 創建變量。
Set regEx = New RegExp ' 創建正則表達式。
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