SoFunction
Updated on 2025-04-13

Common functions used in ASP

Commonly used functions of ASP, I hope they can be used.

<%
dim db
db=""

'******************************************************************
'Execute the SQL statement without returning the value. The best SQL statement is as follows:
'update table name set field name = value, field name = value where field name = value
'delete from table name where field name=value
'insert into table name (field name, field name) values ​​(value,value)
'******************************************************************
Sub NoResult(sql)
dim conn
dim connstr
Set conn = ("")
connstr="Provider=.4.0;Data Source=" & (""&db&"")
connstr
sql

set conn=nothing
End Sub

'*******************************************************************
'Execute the select statement and return the recordset object. This object is read-only. That is, it cannot be updated
'*******************************************************************
Function Result(sql)
dim conn
dim connstr
dim rcs
Set conn = ("")
connstr="Provider=.4.0;Data Source=" & (""&db&"")
connstr
Set rcs = ("")
sql,conn,1,1
set Result = rcs
End Function

'*******************************************************************
' The dialog box pops up
'*******************************************************************
Sub alert(message)
message = replace(message,"'","\'")
("<script>alert('" & message & "')</script>")
End Sub

'*******************************************************************
' Return to the previous page, usually used after judging whether the information is submitted completely
'*******************************************************************
Sub GoBack()
("<script>(-1)</script>")
End Sub

'*******************************************************************
' Redirect another connection
'*******************************************************************
Sub Go(url)
("<script>('" & url & "')</script>")
End Sub

'*******************************************************************
' Replace the html tag
'*******************************************************************

function htmlencode2(str)
dim result
dim l
if isNULL(str) then
htmlencode2=""
exit function
end if
l=len(str)
result=""
dim i
for i = 1 to l
select case mid(str,i,1)
case "<"
result=result+"&lt;"
case ">"
result=result+"&gt;"
case chr(13)
result=result+"<br>"
case chr(34)
result=result+"&quot;"
case "&"
result=result+"&amp;"
case chr(32)
'result=result+"&nbsp;"
if i+1<=l and i-1>0 then
if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then
result=result+"&nbsp;"
else
result=result+" "
end if
else
result=result+"&nbsp;"
end if
case chr(9)
result=result+" "
case else
result=result+mid(str,i,1)
end select
next
htmlencode2=result
end function

'*******************************************************************
' Check whether there are single quotes in the sql string, and if there is, convert it
'*******************************************************************
function CheckStr(str)
dim tstr,l,i,ch
str = Trim(str)
l=len(str)
for i=1 to l
ch=mid(str,i,1)
if ch="'" then
tstr=tstr+"'"
end if
tstr=tstr+ch
next
CheckStr=tstr
end function
%>