再發(fā)幾個(gè)ASP不錯(cuò)的函數(shù)
更新時(shí)間:2007年08月18日 22:37:46 作者:
********************
'函數(shù)作用:根據(jù)條件真假返回選定值中的某個(gè)
'參數(shù):blnCondition:條件變量,varResultTrue:條件為真時(shí)返回值,varResultFalse:條件為假時(shí)返回值
Function IIF(blnCondition, varResultTrue,varResultFalse)
If CBool(blnCondition) Then
IIF = varResultTrue
Else
IIF = varResultFalse
End If
End Function
'********************
'函數(shù)作用:判斷某個(gè)字符串元素是否在給定枚舉中
'參數(shù):sEle:待判斷的字符串,sArray:指定枚舉
'舉例:根據(jù)擴(kuò)展名判斷是否圖片文件: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
'********************
'函數(shù)作用:判斷某個(gè)字符串是否符合正則表達(dá)式
'參數(shù):strString:字符串,strPattern:正則表達(dá)式
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
'********************
'函數(shù)作用:正則提取
'參數(shù):string:字符串,patrn:正則表達(dá)式
'返回:逗號(hào)分割的結(jié)果數(shù)組集成
Function doReExec(strng,patrn)
Dim regEx, Match, Matches,RetStr ' 創(chuàng)建變量。
Set regEx = New RegExp ' 創(chuàng)建正則表達(dá)式。
regEx.Pattern = patrn ' 設(shè)置模式。
regEx.IgnoreCase = True ' 設(shè)置為不區(qū)分大小寫(xiě)。
regEx.Global = True ' 設(shè)置全局適用。
Set Matches = regEx.Execute(strng) ' 執(zhí)行搜索。
For Each Match in Matches ' 對(duì) Matches 集合進(jìn)行迭代。
RetStr = RetStr & Match.Value & "," & vbCRLF
Next
doReExec = RetStr
End Function
復(fù)制代碼 '********************
'函數(shù)作用:顯示分頁(yè)鏈接
'參數(shù):lngCurPage:當(dāng)前頁(yè)是第幾頁(yè),lngPageCount:一共幾頁(yè),strSueryString:分頁(yè)鏈接需要附加的QueryString變量
Sub showPageNav(lngCurPage,lngPageCount,ByVal strQueryString)
Response.Write "當(dāng)前第" & lngCurPage & "頁(yè),共:" & lngPageCount & "頁(yè)"
Dim i,j,k
If lngCurPage = 1 Then '如果是第一頁(yè)
'如果lngPageCount小于10,則導(dǎo)航頁(yè)最多到lngPageCount頁(yè)
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 '如果是最后一頁(yè)
'如果lngPageCount小于10,則導(dǎo)航起始從1開(kāi)始
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 '如果是中間的頁(yè)
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
'********************
'函數(shù)作用:當(dāng)前頁(yè)請(qǐng)求方式是否為POST
'說(shuō)明:用于在同一頁(yè)面處理顯示和數(shù)據(jù)操作,當(dāng)PostBack()為真時(shí)說(shuō)明提交表單至當(dāng)前頁(yè),應(yīng)進(jìn)行數(shù)據(jù)后臺(tái)操作
Function PostBack()
If UCase(Trim(Request.ServerVariables("REQUEST_METHOD"))) = "POST" Then
PostBack = True
Else
PostBack = False
End If
End Function
'********************
'函數(shù)作用:返回執(zhí)行長(zhǎng)度的隨機(jī)字符串
'參數(shù):Length:長(zhǎng)度
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
'函數(shù)作用:根據(jù)條件真假返回選定值中的某個(gè)
'參數(shù):blnCondition:條件變量,varResultTrue:條件為真時(shí)返回值,varResultFalse:條件為假時(shí)返回值
Function IIF(blnCondition, varResultTrue,varResultFalse)
If CBool(blnCondition) Then
IIF = varResultTrue
Else
IIF = varResultFalse
End If
End Function
'********************
'函數(shù)作用:判斷某個(gè)字符串元素是否在給定枚舉中
'參數(shù):sEle:待判斷的字符串,sArray:指定枚舉
'舉例:根據(jù)擴(kuò)展名判斷是否圖片文件: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
'********************
'函數(shù)作用:判斷某個(gè)字符串是否符合正則表達(dá)式
'參數(shù):strString:字符串,strPattern:正則表達(dá)式
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
'********************
'函數(shù)作用:正則提取
'參數(shù):string:字符串,patrn:正則表達(dá)式
'返回:逗號(hào)分割的結(jié)果數(shù)組集成
Function doReExec(strng,patrn)
Dim regEx, Match, Matches,RetStr ' 創(chuàng)建變量。
Set regEx = New RegExp ' 創(chuàng)建正則表達(dá)式。
regEx.Pattern = patrn ' 設(shè)置模式。
regEx.IgnoreCase = True ' 設(shè)置為不區(qū)分大小寫(xiě)。
regEx.Global = True ' 設(shè)置全局適用。
Set Matches = regEx.Execute(strng) ' 執(zhí)行搜索。
For Each Match in Matches ' 對(duì) Matches 集合進(jìn)行迭代。
RetStr = RetStr & Match.Value & "," & vbCRLF
Next
doReExec = RetStr
End Function
復(fù)制代碼 '********************
'函數(shù)作用:顯示分頁(yè)鏈接
'參數(shù):lngCurPage:當(dāng)前頁(yè)是第幾頁(yè),lngPageCount:一共幾頁(yè),strSueryString:分頁(yè)鏈接需要附加的QueryString變量
Sub showPageNav(lngCurPage,lngPageCount,ByVal strQueryString)
Response.Write "當(dāng)前第" & lngCurPage & "頁(yè),共:" & lngPageCount & "頁(yè)"
Dim i,j,k
If lngCurPage = 1 Then '如果是第一頁(yè)
'如果lngPageCount小于10,則導(dǎo)航頁(yè)最多到lngPageCount頁(yè)
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 '如果是最后一頁(yè)
'如果lngPageCount小于10,則導(dǎo)航起始從1開(kāi)始
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 '如果是中間的頁(yè)
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
'********************
'函數(shù)作用:當(dāng)前頁(yè)請(qǐng)求方式是否為POST
'說(shuō)明:用于在同一頁(yè)面處理顯示和數(shù)據(jù)操作,當(dāng)PostBack()為真時(shí)說(shuō)明提交表單至當(dāng)前頁(yè),應(yīng)進(jìn)行數(shù)據(jù)后臺(tái)操作
Function PostBack()
If UCase(Trim(Request.ServerVariables("REQUEST_METHOD"))) = "POST" Then
PostBack = True
Else
PostBack = False
End If
End Function
'********************
'函數(shù)作用:返回執(zhí)行長(zhǎng)度的隨機(jī)字符串
'參數(shù):Length:長(zhǎng)度
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
相關(guān)文章
ASP獲取ACCESS數(shù)據(jù)庫(kù)表名及結(jié)構(gòu)的代碼
此方法可獲得ACCESS數(shù)據(jù)的表名及其結(jié)構(gòu),數(shù)據(jù)類型等... 程序過(guò)濾了幾個(gè)ACCESS數(shù)據(jù)庫(kù)的幾個(gè)隱藏表(可能是導(dǎo)致ACCESS數(shù)據(jù)庫(kù)刪除數(shù)據(jù)還會(huì)變大的原因)2008-08-08
ASP批量生成靜態(tài)頁(yè)面的寫(xiě)法(批量生成技巧iframe)
自己快忘的ASP批量生成寫(xiě)法,需要自己寫(xiě)asp生成靜態(tài)頁(yè)面的朋友可以參考下。2011-01-01
在Vista IIS 7 中用 vs2005 調(diào)試 Web 項(xiàng)目的注意事項(xiàng)
在Vista IIS 7 中用 vs2005 調(diào)試 Web 項(xiàng)目核心是要解決以下幾個(gè)問(wèn)題2008-09-09
asp去除html的函數(shù)代碼分析附實(shí)例說(shuō)明
asp去除html的函數(shù)代碼分析附實(shí)例說(shuō)明,經(jīng)腳本之家編程測(cè)試確實(shí)好用。2012-01-01

