asp教程開發中常用函數
sub lastnextpage(pagecount,page,table_style,font_style)
'產生上一頁下一頁連結
dim query, a, x, temp
action = "http://" & request.servervariables("http_host") & request.servervariables("script_name")
query = split(request.servervariables("query_string"), "&")
for each x in query
a = split(x, "=")
if strcomp(a(0), "page", vbtextcompare) <> 0 then
temp = temp & a(0) & "=" & a(1) & "&"
end if
next
response.write("<table " & table_style & ">" & vbcrlf )
response.write("<form method=get onsubmit=""document.location = '" & action & "?" & temp & "page='+ this.page.value;return false;""><tr>" & vbcrlf )
response.write("<td align=right>" & vbcrlf )
response.write(font_style & vbcrlf )
if page<=1 then
response.write ("<img src='images/index.gif' alt='首頁' width='72' height='17' border='0'> " & vbcrlf)
response.write ("<img src='images/pre01.gif' alt='上一頁' width='72' height='17' border='0'> " & vbcrlf)
else
response.write("<a href=" & action & "?" & temp & "page=1><img src='images/index.gif' alt='首頁' width='72' height='17' border='0'></a> " & vbcrlf)
response.write("<a href=" & action & "?" & temp & "page=" & (page-1) & "><img src='images/pre01.gif' alt='上一頁' width='72' height='17' border='0'></a> " & vbcrlf)
end if
if page>=pagecount then
response.write ("<img src='images/next01.gif' alt='下一頁' width='72' height='17' border='0'> " & vbcrlf)
response.write ("<img src='images/end.gif' alt='尾頁' width='72' height='17' border='0'>" & vbcrlf)
else
response.write("<a href=" & action & "?" & temp & "page=" & (page+1) & "><img src='images/next01.gif' alt='下一頁' width='72' height='17' border='0'></a> " & vbcrlf)
response.write("<a href=" & action & "?" & temp & "page=" & pagecount & "><img src='images/end.gif' alt='尾頁' width='72' height='17' border='0'></a>" & vbcrlf)
end if
response.write(" 當前 <font color=red><b>" & page & "/" & pagecount & "</b></font> 頁" & vbcrlf)
'response.write(" 共 <font color=red><b>" & all_num & "</b></font> 條" & vbcrlf)
response.write(" 第" & "<input tyep=text name=page size=2 maxlength=5 style='height: 17' value='" & page & "'>" & "頁" & vbcrlf & "<input type=submit style=""height: 16; font-size: 7pt"" value=go>")
response.write("</td>" & vbcrlf )
response.write("</tr></form>" & vbcrlf )
response.write("</table>" & vbcrlf )
end sub
sub chkfod(fstring)
if trim(fstring) <> empty then
if right(fstring, 1) <> "/" then
fstring = fstring & "/"
end if
dim i, tempdir
fstring = split(fstring, "/")
for i = 1 to ubound(fstring)
if trim(fstring(i)) <> empty then
tempdir = tempdir & "/" & fstring(i)
set fso = createobject("scripting.filesystemobject")
if fso.folderexists(server.mappath(tempdir)) = false then
fso.createfolder (server.mappath(tempdir))
end if
set fso = nothing
else
exit for
end if
next
end if
end sub
rem 設定隨機數字
function cdstr(dlen)
'response.write cdstr(9) ''指定長度為9的隨機字串
dim ss,sslen
randomize timer
ss="1234567890"
sslen = len(ss)
cdstr = ""
for i = 1 to dlen
t = cint(rnd*sslen)+1 ''這裡加1,不然出現mid(ss,0,1)會出錯
cdstr = cdstr&mid(ss,t,1)
next
end function
'檢查字串長度
function strlength(str)
on error resume next
dim winnt_chinese
winnt_chinese = (len("論壇")=2)
if winnt_chinese then
dim l,t,c
dim i
l=len(str)
t=l
for i=1 to l
c=asc(mid(str,i,1))
if c<0 then c=c+65536
if c>255 then
t=t+1
end if
next
strlength=t
else
strlength=len(str)
end if
if err.number<>0 then err.clear
end function