A few more ASP good functions _ Application Tips

Source: Internet
Author: User
********************
' Function: Return one of the selected values according to the condition
' Parameters: blncondition: Condition variable, varresulttrue: return value when condition is true, Varresultfalse: return value when condition is false
Function IIF (blncondition, Varresulttrue,varresultfalse)
If CBool (blncondition) Then
IIF = Varresulttrue
Else
IIF = Varresultfalse
End If
End Function

'********************
' function: To determine whether a string element is in a given enumeration
' Parameter: Sele: The string to be judged, Sarray: Specify Enumeration
' Example: According to the extension to determine whether the picture file: 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
'********************
' function: To determine whether a string conforms to a regular expression
' Parameters: strstring: String, Strpattern: Regular expression
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
'********************
' Functional function: Regular extraction
' Parameters: String: Strings, Patrn: Regular Expressions
' Return: comma-separated result array integration
Function doreexec (STRNG,PATRN)
Dim regEx, Match, matches,retstr ' Create variable.
Set regEx = New RegExp ' creates a regular expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = True ' is set to case-insensitive.
Regex.global = True ' Sets global applicability.
Set matches = Regex.execute (strng) ' performs a search.
For the Match in matches ' iterates over the matches collection.
Retstr = retstr & Match.value & "," & VbCRLF
Next
Doreexec = Retstr
End Function
Copy Code ' ********************
' Function: Show page links
' Parameters: Lngcurpage: The current page is the first few pages, Lngpagecount: A total of several pages, strsuerystring: Page links need additional QueryString variables
Sub Showpagenav (Lngcurpage,lngpagecount,byval strquerystring)
Response.Write "Current & lngcurpage &" page, Total: "& lngpagecount &" page
Dim i,j,k
If lngcurpage = 1 Then ' If this is the first page
' If Lngpagecount is less than 10, the navigation page is up to Lngpagecount page
If Lngpagecount < 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 ' If it's the last page
' If the lngpagecount is less than 10, the navigation starts at 1
If Lngpagecount < 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 it's the middle page
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 & "" > "&" >> "&am P "</a>")
End If
End Sub
'********************
' function: Whether the current page request method is post
' Description: Used on the same page to handle display and data operations, when postback () is true when the submission of the form to the current page, you should do data background operation
Function postback ()
If UCase (Trim (Request.ServerVariables ("Request_method")) = "POST" Then
postback = True
Else
postback = False
End If
End Function
'********************
' function: Returns a random string of execution lengths
' Parameters: Length: Lengths
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 (a) = "J": C (one) = "K": C (a) = "L": c () = "M": c (= "n")
c = "O": c = "P": C (m) = "Q": C (m) = "R": C (P) = "s": c () = "T": c () = "U"
C () = "V": C (k) = "W": C (a) = "X": c (= "Y": c () = "Z": C (m) = "1": C (28) = "2"
(c) = "3": c = "4": C (to) = "5": C (m) = "6": C (m) = "7": C (MB) = "8": C (35) = "9"
If IsNumeric (Length) = False Then
Response.Write "A Numeric datatype is not submitted to this function."
Exit Function
End If
For i = 1 to Length
Randomize
v = Int ((Rnd) + 1)
TempS = TempS & C (v)
Next
genradomstring = TempS
End Function
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.