常用ASP自定义函数全集(4)_ASP教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:解读ASP常见错误类型大全
ActiveServerPages,ASP0126(0x80004005)--找不到包含文件 MicrosoftOLEDBProviderforODBCDrivers(0x80040E21)--sql语句出错(数据类型不匹配或表名(字段名)错误或表处于编辑状态,或表不存在于conn打开的数据库中) MicrosoftOLEDBProviderforODBCDrivers(0x800


'判断文件夹是否存在
Function Checkfolder(folderpath)
   Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
     If objFSO.FolderExists(Server.MapPath(""&folderpath&"")) Then
   Else
    objFSO.CreateFolder(Server.MapPath(""&folderpath&""))'不存在就建一个目录
   End If
   Set objFSO = Nothing
End Function
'--------------------------------
'删除文件夹
Function Deletefolder(folderpath)
   Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
       If objFSO.FolderExists(Server.MapPath(""&folderpath&"")) Then
    objFSO.deletefolder(server.MapPath(folderpath))
    end if
   Set objFSO = Nothing
End Function
'--------------------------------
'一套加解密字符串的函数,基本正确   ,最多8位
Function Encrypt(theNumber)
On Error Resume Next
Dim n, szEnc, t, HiN, LoN, i
n = CDbl((theNumber + 1570) ^ 2 - 7 * (theNumber + 1570) - 450)
If n < 0 Then szEnc = "R" Else szEnc = "J"
n = CStr(abs(n))
For i = 1 To Len(n) step 2
t = Mid(n, i, 2)
If Len(t) = 1 Then
szEnc = szEnc & t
Exit For
End If
HiN = (CInt(t) And 240) / 16
LoN = CInt(t) And 15
szEnc = szEnc & Chr(Asc("M") + HiN) & Chr(Asc("C") + LoN)
Next
Encrypt = szEnc
End Function

Function Decrypt(theNumber)
On Error Resume Next
Dim e, n, sign, t, HiN, LoN, NewN, i
e = theNumber
If Left(e, 1) = "R" Then sign = -1 Else sign = 1
e = Mid(e, 2)
NewN = ""
For i = 1 To Len(e) step 2
t = Mid(e, i, 2)
If Asc(t) >= Asc("0") And Asc(t) <= Asc("9") Then
NewN = NewN & t
Exit For
End If
HiN = Mid(t, 1, 1)
LoN = Mid(t, 2, 1)
HiN = (Asc(HiN) - Asc("M")) * 16
LoN = Asc(LoN) - Asc("C")
t = CStr(HiN Or LoN)
If Len(t) = 1 Then t = "0" & t
NewN = NewN & t
Next
e = CDbl(NewN) * sign
Decrypt = CLng((7 + sqr(49 - 4 * (-450 - e))) / 2 - 1570)
End Function
'--------------------------------
'函数功能:将指定的文件内容读出
'相关参数:FileName
'返回值:   文件全部内容
Function readfilerecord(Filename)
if instr(filename,".")=0 then exit function
set ffso=server.createobject("scripting.filesystemobject")
if ffso.FileExists(server.mappath(filename))=false then exit function
set re_ffso=ffso.OpenTextFile(server.mappath(filename),1,0,0)
readfilerecord=re_ffso.readall
re_ffso.close
set ffso=nothing
end function
'---------------------------------

分享:ASP实现长文章手动分页的代码
% setrecordset1=server.createobject(adodb.recordset) exec=SELECT*FROMnewswhereid=id recordset1.Openexec,conn,1,1 % tablewidth=85%border=0align=centercellpadding=3cellspacing=0 trtd ....... % IfRequest(page)=Then pageNum=0

来源:模板无忧//所属分类:ASP教程/更新时间:2010-04-10
相关ASP教程