asp最簡(jiǎn)單最實(shí)用的計(jì)數(shù)器
更新時(shí)間:2007年09月17日 13:11:27 作者:
剛才找一個(gè)計(jì)數(shù)器,由于網(wǎng)站的訪問(wèn)量太少,放個(gè)計(jì)數(shù)器在那里確實(shí)有點(diǎn)寒酸了,于是呼只能搞一個(gè)簡(jiǎn)單點(diǎn)的,可以訪問(wèn)一次就記錄一次的來(lái)?yè)螕伍T面先。本來(lái)以前我有一個(gè),但是郁悶的是居然找不到了,在網(wǎng)上SO了一圈,總算是搞定了,具體程序代碼如下。
count.asp的代碼為:
<%
option explicit
dim fs,filename,txt,content,total,counter_lenth
counter_lenth=1 '設(shè)置顯示數(shù)據(jù)的最小長(zhǎng)度,如果小于實(shí)際長(zhǎng)度則以實(shí)際長(zhǎng)度為準(zhǔn)
set fs=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("count.txt")
if not fs.FileExists(filename) then
fs.CreateTextFile filename,True,True
set txt=fs.OpenTextFile(filename,2,true)
txt.write 0 '如不存在保存數(shù)據(jù)的文件則創(chuàng)建新文件并寫入數(shù)據(jù)0
set fs=nothing
end if
set txt=fs.OpenTextFile(filename)
If txt.AtEndOfStream Then
Application("Counter")=0 '如果文件中沒(méi)有數(shù)據(jù),則初始化Application("Counter")的值(為了容錯(cuò))
else
Application("Counter")=txt.readline
end if
Application.Lock
Application("Counter") = Application("Counter") + 1
Application.UnLock
Function save_ '保存計(jì)數(shù)函數(shù)
set fs=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("count.txt")
content=Application("Counter")
set txt=fs.OpenTextFile(filename,2,true)
txt.write content
set fs=nothing
End Function
save_ '調(diào)用保存函數(shù)保存數(shù)據(jù)
Function Digital ( counter ) '顯示數(shù)據(jù)函數(shù)
Dim i,MyStr,sCounter
sCounter = CStr(counter)
For i = 1 To counter_lenth - Len(sCounter)
MyStr = MyStr & "0"
'MyStr = MyStr & "<IMG SRC=改成你自己的圖片存放的相對(duì)目錄\0.gif>" '如有圖片,可用此語(yǔ)句調(diào)用
Next
For i = 1 To Len(sCounter)
MyStr = MyStr & Mid(sCounter, i, 1)
'MyStr = MyStr & "<IMG SRC=改成你自己的圖片存放的相對(duì)目錄\" & Mid(sCounter, i, 1) & ".gif>" '如有圖片,可用此語(yǔ)句調(diào)用
Next
Digital = MyStr
End Function
Function count_show '讀取計(jì)數(shù)函數(shù)
set fs=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("count.txt")
set txt=fs.opentextfile(filename,1,true)
total=txt.readline
total=cint(total)
'response.write total
response.write Digital (total) '調(diào)用顯示函數(shù)
set fs=nothing
End Function
%>
然后新建一個(gè)count.txt(必須和count.asp同一級(jí)目錄),打開(kāi)這個(gè)文件后在里面輸入任意數(shù)字(別太狠啦),然后在需要顯示計(jì)數(shù)器的那個(gè)頁(yè)面頂部加入
<!--#include file="count.asp"-->
最后在需要顯示計(jì)數(shù)器的地方加上代碼
<%=count_show%>
就OK了。
count.asp的代碼為:
復(fù)制代碼 代碼如下:
<%
option explicit
dim fs,filename,txt,content,total,counter_lenth
counter_lenth=1 '設(shè)置顯示數(shù)據(jù)的最小長(zhǎng)度,如果小于實(shí)際長(zhǎng)度則以實(shí)際長(zhǎng)度為準(zhǔn)
set fs=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("count.txt")
if not fs.FileExists(filename) then
fs.CreateTextFile filename,True,True
set txt=fs.OpenTextFile(filename,2,true)
txt.write 0 '如不存在保存數(shù)據(jù)的文件則創(chuàng)建新文件并寫入數(shù)據(jù)0
set fs=nothing
end if
set txt=fs.OpenTextFile(filename)
If txt.AtEndOfStream Then
Application("Counter")=0 '如果文件中沒(méi)有數(shù)據(jù),則初始化Application("Counter")的值(為了容錯(cuò))
else
Application("Counter")=txt.readline
end if
Application.Lock
Application("Counter") = Application("Counter") + 1
Application.UnLock
Function save_ '保存計(jì)數(shù)函數(shù)
set fs=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("count.txt")
content=Application("Counter")
set txt=fs.OpenTextFile(filename,2,true)
txt.write content
set fs=nothing
End Function
save_ '調(diào)用保存函數(shù)保存數(shù)據(jù)
Function Digital ( counter ) '顯示數(shù)據(jù)函數(shù)
Dim i,MyStr,sCounter
sCounter = CStr(counter)
For i = 1 To counter_lenth - Len(sCounter)
MyStr = MyStr & "0"
'MyStr = MyStr & "<IMG SRC=改成你自己的圖片存放的相對(duì)目錄\0.gif>" '如有圖片,可用此語(yǔ)句調(diào)用
Next
For i = 1 To Len(sCounter)
MyStr = MyStr & Mid(sCounter, i, 1)
'MyStr = MyStr & "<IMG SRC=改成你自己的圖片存放的相對(duì)目錄\" & Mid(sCounter, i, 1) & ".gif>" '如有圖片,可用此語(yǔ)句調(diào)用
Next
Digital = MyStr
End Function
Function count_show '讀取計(jì)數(shù)函數(shù)
set fs=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("count.txt")
set txt=fs.opentextfile(filename,1,true)
total=txt.readline
total=cint(total)
'response.write total
response.write Digital (total) '調(diào)用顯示函數(shù)
set fs=nothing
End Function
%>
然后新建一個(gè)count.txt(必須和count.asp同一級(jí)目錄),打開(kāi)這個(gè)文件后在里面輸入任意數(shù)字(別太狠啦),然后在需要顯示計(jì)數(shù)器的那個(gè)頁(yè)面頂部加入
復(fù)制代碼 代碼如下:
<!--#include file="count.asp"-->
最后在需要顯示計(jì)數(shù)器的地方加上代碼
復(fù)制代碼 代碼如下:
<%=count_show%>
就OK了。
相關(guān)文章
忠網(wǎng)廣告 系統(tǒng) 用到的幾個(gè)函數(shù)
忠網(wǎng)廣告 系統(tǒng) 用到的幾個(gè)函數(shù)...2006-11-11ASP中解決“對(duì)象關(guān)閉時(shí),不允許操作?!钡脑幃悊?wèn)題……
本文解決ASP中“對(duì)象關(guān)閉時(shí),不允許操作?!钡脑幃悊?wèn)題,找到問(wèn)題的根本,才能真正意義上解決,供大家參考了。2016-03-03微信開(kāi)發(fā) 網(wǎng)頁(yè)授權(quán)獲取用戶基本信息
這篇文章主要介紹了微信開(kāi)發(fā) 網(wǎng)頁(yè)授權(quán)獲取用戶基本信息的相關(guān)資料,需要的朋友可以參考下2016-09-09asp 實(shí)現(xiàn)顯示所有的服務(wù)器變量值的函數(shù)
asp 實(shí)現(xiàn)顯示所有的服務(wù)器變量值的函數(shù)...2007-08-08asp取整數(shù)mod 有小數(shù)的就自動(dòng)加1
這篇文章主要介紹了asp取整數(shù)mod 有小數(shù)的就自動(dòng)加1,需要的朋友可以參考下2021-04-04