ASP中的自定义函数

一 隐藏执行时间
  Sub s__HideTimeOver()
   Dim tTimeOver
   tTimeOver = FormatNumber((Timer() - tStartTime) * 1000, 3, true)
   response.Write(vbCrLf & "<!--执行时间: " & tTimeOver & " 毫秒-->")
  End Sub

二 打开数据库连接
  function f__OpenConn()
   Dim connstr
   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

三 关闭数据库连接
  function f__CloseConn()
   If IsObject(conn) Then
    Set conn = nothing
   End If
  End function

四 HTML 转换
  function toHtml(str)
   Dim Result
   Result = str & ""
   
   Result = replace(Result, ">", ">")
   Result = replace(Result, "<", "<")
   Result = replace(Result, " ", " ")
   Result = replace(Result, """", """)
   Result = replace(Result, CHR(13), "")
   Result = replace(Result, CHR(10), "<br>")
   Result = replace(Result, CHR(39), "'")
   
   toHtml = Result
  End function
 
五 长整数转换
  function toLng(strNum, Default)
   Dim Result
   
   If  strNum <> "" And IsNumeric(strNum) Then
    Result = CLng(strNum)
   Else
    toNum = Default
   End If
   
   toLng = Result
  End function

六 货币类型转换
  function toCur(strNum, Default)
   Dim Result
   
   If  strNum <> "" And IsNumeric(strNum) Then
    Result = CCur(strNum)
   Else
    toNum = Default
   End If
   
   toCur = Result
  End function

七 SQL 替换编码
  function toSqlr(str)
   str = str & ""
   str = replace(str, "'", "")
   str = replace(str, """", "")
   
   toSqlr = str
  End function

八 SQL 编码
  function toSql(str)
   str = str & ""
   str = replace(str, "'", "''")
  
   toSql = str
  End function

九 转换数字为固定位数, 不足位补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

原文地址:https://www.cnblogs.com/LiaoHao/p/3525650.html