Some common ASP User-Defined Functions

Source: Internet
Author: User
Tags servervariables

The following functions are my summary over the years. Some of them are constantly summed up at work, and some are collected through some network routines. I hope these functions will be helpful to you, thank you!

'Custom formatdatetime function FormatType parameter item
Const fddefadatetime datetime = 1' format: yyyy-m-d h: m: s
Const fdDefaultDate = 2' format: yyyy-m-d
Const fdDefaultTime = 3' format: h: m: s
Const fdChineseDate = 4' format: yyyy-mm-dd
Const fdLongDateTime = 5' format: yyyy-mm-dd hh: mm: ss
Const fdLongDate = 6' format: yyyy-mm-dd
Const fdLongTime = 7' format: hh: mm: ss

'Obtain the mode parameter of the QueryString, Form, Cookies, ServerVariables value GetRequestValue function.
Const gvALL = 1' equals to: request ("key ")
Const gvForm = 2' equals to: request. form ("key ")
Const gvQuery = 3' equal to: request. QueryString ("key ")
Const gvCookies = 4' equals to: request. Cookies ("key ")
Const gvIP = 5' equal to: Request. ServerVariables ("REMOTE_ADDR ")
Const gvURL = 6' equals to: Request. ServerVariables ("URL ")

'Custom function CheckInput function ype Parameter
Const ciNumber = 1
Const ciString = 2
Const ciDateTime = 3

'*************************************** ******************
'Purpose: to format the date output
'
'Input: data: number to be output
'Formattype: Date Format
'Const fddefadatetime datetime = 1' format: yyyy-m-d h: m: s
'Const fddefadate date = 2' format: yyyy-m-d
'Const fdDefaultTime = 3' format: h: m: s
'Const fdChineseDate = 4' format: yyyy-mm-dd
'Const fdLongDateTime = 5' format: yyyy-mm-dd hh: mm: ss
'Const fdLongDate = 6' format: yyyy-mm-dd
'Const fdLongTime = 7' format: hh: mm: ss
'
'Return value: formatted date string
'
'*************************************** ******************
Function MyFormatDateTime (data, FormatType)
If not (isdate (data) then data = date
Select case FormatType
Case fddefadatetime datetime
Data = year (data) & "-" & month (data) & "-" & day (data) & "& hour (data )&": "& minute (data) &": "& second (data)
Case fdDefaultDate
Data = year (data) & "-" & month (data) & "-" & day (data)
Case fdDefaultTime
Data = hour (data) & ":" & minute (data) & ":" & second (data)
Case fdChineseDate
Data = year (data) & "year" & month (data) & "month" & day (data) & "day"
Case fdLongDateTime
Data = year (data) & "-" & MyFormatNumber (month (data), 2) & "-" & MyFormatNumber (day (data), 2) & "" & MyFormatNumber (hour (data), 2) & ":" & MyFormatNumber (minute (data), 2) & ":" & MyFormatNumber (second (data ), 2)
Case fdLongDate
Data = year (data) & "-" & MyFormatNumber (month (data), 2) & "-" & MyFormatNumber (day (data), 2)
Case fdLongTime
Data = MyFormatNumber (hour (data), 2) & ":" & MyFormatNumber (minute (data), 2) & ":" & MyFormatNumber (second (data), 2)
End Select
MyFormatDateTime = data
End Function

'*************************************** ******************
'Purpose: to format the digital output
'
'Input: data: number to be output
'Numlength: the length of the number to be output.
'Example: data = 1 NumLength = 3 return 001
'Data = 11 NumLength = 5 returns 00011
'
'Return value: formatted numeric string
'
'*************************************** ******************
Function MyFormatNumber (data, NumLength)
Dim FillLength
Filllength = NumLength-len (data)
MyFormatNumber = String (Filllength, "0") & data
End Function

'*************************************** ******************
'Purpose: to encode the output string in HTML Format
'
'Input: p_STR: the character to be output
'
'Return value: the replaced string
'
'*************************************** ******************
Function HTMLEncode (p_STR)
If not isnull (p_STR) then
P_STR = replace (p_STR, ">", "& gt ;")
P_STR = replace (p_STR, "<", "& lt ;")
P_STR = Replace (p_STR, CHR (32), "& nbsp ;")
P_STR = Replace (p_STR, CHR (9), "& nbsp ;")
P_STR = Replace (p_STR, CHR (34), "& quot ;")
P_STR = Replace (p_STR, CHR (39), "& #39 ;")
P_STR = Replace (p_STR, CHR (13), "<BR> ")
HTMLEncode = p_STR
End if
End Function

'*************************************** ******************
'Purpose: to replace the output string with UBB
'
'Input: p_STR: string to be output
'
'Return value: the replaced string
'
'*************************************** ******************
Function UBBCode (p_STR)
P_STR = HTMLEncode (p_STR)
Dim re
Set re = new RegExp
Re. IgnoreCase = true
Re. Global = True

Re. Pattern = "(? :/[IMG/]) (. [^/[] *) (? :/[// IMG/])"
StrContent = re. replace (p_STR, "<div width = '000000' align = 'center'> </div> ")
Re. Pattern = "(? :/[B/]) (. [^/[] *) (? :/[// B/])"
StrContent = re. Replace (p_STR, "<B> $1 </B> ")
Re. Pattern = "(? :/[URL = (. [^/[] *)/]) (. [^/[] *) (? :/[// URL/])"
StrContent = re. Replace (p_STR, "<a href =" "$1" "target =" "_ blank" ">2 2 </a> ")
Set re = Nothing
UBBCode = p_STR
End function

'*************************************** ******************
'Objective: to replace response. write p_Str
'
'Input: p_STR: string to be output
'
'Return value: None
'
'*************************************** ******************
Function echo (p_STR)
Response. write p_Str
End function

'*************************************** ******************
'Purpose: to replace response. write p_Str & "<br>"
'Response. end
'
'Input: p_STR: string to be output
'
'Return value: None
'
'*************************************** ******************
Function die (p_STR)
Echo p_Str
Response. end
End function

'*************************************** ******************
'Purpose: to replace response. write p_Str & "<br>"
'
'Input: p_STR: string to be output
'
'Return value: None
'
'*************************************** ******************
Function echobr (p_STR)
Echo p_Str & "<br>" & vbCRLF
End function

'*************************************** ******************
'Purpose: to replace request. cookies ("key") = p_STR
'
'Input: key: Output keyword
'P_STR: string to be output
'Pexpires: cookie time
'
'Return value: None
'
'*************************************** ******************
Function echock (key, p_STR, pExpires)
Response. cookies (key) = p_STR
If not (isnull (pExpires) or pExpires = "") then response. cookies (key). Expires = pExpires
End Function

'*************************************** ******************
'Purpose: to replace the value of the Request
'
'Input: key of the value
'Pmode: Value Method
'Const gvALL = 1' equals to: request ("key ")
'Const gvForm = 2' equals to: request. form ("key ")
'Const gvQuery = 3' equals to: request. QueryString ("key ")
'Const gvCookies = 4' equals to: request. Cookies ("key ")
'Const gvIP = 5' equals to: Request. ServerVariables ("REMOTE_ADDR ")
'Const gvURL = 6' equals to: Request. ServerVariables ("URL ")
'
'Return value: return the value after the request.
'
'*************************************** ******************
Function GetRequestValue (key, pMode)
Dim p_STR
Select Case pMode
Case gvALL
P_STR = request (key)
Case gvForm
P_STR = request. form (key)
Case gvQuery
P_STR = request. querystring (key)
Case gvCookies
P_STR = request. cookies (key)
Case gvIP
P_STR = Request. ServerVariables ("REMOTE_ADDR ")
Case gvURL
P_STR = Request. ServerVariables ("URL ")
End Select
GetRequestValue = p_STR
End Function

'*************************************** ******************
'Purpose: to check the type of data submitted by the user
'
'Input: exp1: Data to be checked
'Ype ype: the data type to be checked.
'Cinumber: Number
'Cistring: character
'Cidatetime: Date
'Defaultvalue: default value.
'Return value: if the data passes the check, the original value is returned. The character type must be replaced by single quotation marks.
'If not, the default value is returned.
'*************************************** ******************
Function CheckInput (exp1, DataType, DefaultValue)
Dim exp2
If isnull (exp1) or exp1 = "" then
Exp2 = DefaultValue
Else
Select Case DataType
Case ciString
Exp2 = Replace (exp1 ,"'","''")
Case ciNumber
If isNumeric (exp1) then
Exp2 = exp1
Else
Exp2 = DefaultValue
End if
Case ciDateTime
If isdate (exp1) then
Exp2 = exp1
Else
Exp2 = DefaultValue
End if
End select
End if
CheckInput = exp2
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.