My most common ASP User-Defined Functions
Author: Xiao Yue mark
<% REM ##################################### ################################# REM ## hide the execution time sub S _ hidetimeover () dim ttimeover = formatnumber (timer ()-tstarttime) * 1000, 3, true) response. write (vbcrlf & "<! -- Execution time: "& ttimeover &" millisecond --> ") end sub REM ##################################### ################################# REM ###### ######################################## ####################### REM ## open the database connection function F _ openconn () dim connstr = "provider = Microsoft. jet. oledb.4.0; Data Source = "connstr = connstr & server. mappath (gbl__str_db_path) set conn = server. createobject ("ADODB. connection ") Conn. open connstr end function REM ################################### ################################### REM #### ######################################## ######################### REM # disable database connection function F _ closeconn () if isobject (conn) then set conn = nothing end if end function REM ############################## ######################################## rem ####################################### ############################### REM ## HTML Conversion Function tohtml (Str) dim result = STR & "" result = Replace (result, ">", "& gt;") Result = Replace (result, "<", "& lt ;") result = Replace (result, "", "& nbsp;") Result = Replace (result, "," & quot; ") Result = Replace (result, CHR (13), "") Result = Replace (result, CHR (10), "<br>") Result = Replace (result, CHR (39 ), "& #39 ;") tohtml = Result end function REM ################################## #################################### REM ### ######################################## ########################## REM # function tolng (strnum, default) dim result if strnum <> "" And isnumeric (strnum) then result = clng (strnum) else tonum = default end if tolng = Result end function REM ############################ ######################################## # REM ##################################### ################################# REM ## currency type Conversion Function tocur (strnum, default) dim result if strnum <> "" And isnumeric (strnum) then result = ccur (strnum) else tonum = default end if tocur = Result end function REM ############################ ######################################## # REM ##################################### ################################# REM ## Replace the encoding function with SQL tosqlr (STR) STR = STR & "" str = Replace (STR, "'", "") STR = Replace (STR ,"""","") tosqlr = STR end function REM ################################## #################################### REM ### ######################################## ########################## REM # SQL coding function tosql (STR) STR = STR & "" str = Replace (STR ,"'","''") tosql = STR end function REM ################################## #################################### REM ### ######################################## ########################## REM # convert a number to a fixed digit, deficiency fill 0 Function convertnumber (strnum) strnum = strnum & "" dim ilen, imaxl, ildiv, result ilen = Len (strnum) imaxl = 8 ildiv = imaxl-ilen result = string (ildiv, "0 ") & strnum convertnumber = Result end function REM ################################ #######################################%>