简单记数器代码|Erentan's赐教

1

本文作者:laibu  发布于:2007-5-14  分类:网站制作  点击:


这个文章是Erentan's Blog 转载过来了的.因为比较喜欢,又一时来不急学会.更重要的是加了注释.我最喜欢看这样的代码了.

暂时收藏了.喜欢的朋友呢 也来看看.

具体内容为:
  count.asp的代码为:

<%
    option explicit
  dim fs,filename,txt,content,total,counter_lenth
  counter_lenth=1  '设置显示数据的最小长度,如果小于实际长度则以实际长度为准
  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 '如不存在保存数据的文件则创建新文件并写入数据0
    set fs=nothing
  end if
  
  set txt=fs.OpenTextFile(filename)
  If txt.AtEndOfStream Then
    Application("Counter")=0 '如果文件中没有数据,则初始化Application("Counter")的值(为了容错)
  else
    Application("Counter")=txt.readline
  end if

  Application.Lock 
  Application("Counter") = Application("Counter") + 1
  Application.UnLock
  

  Function save_ '保存计数函数
  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_  '调用保存函数保存数据

  Function Digital ( counter )  '显示数据函数
    Dim i,MyStr,sCounter
     sCounter = CStr(counter)
    For i = 1 To counter_lenth - Len(sCounter)
      MyStr = MyStr & "0"
    'MyStr = MyStr & "<IMG SRC=改成你自己的图片存放的相对目录\0.gif>" '如有图片,可用此语句调用
    Next
    For i = 1 To Len(sCounter)
      MyStr = MyStr & Mid(sCounter, i, 1)
    'MyStr = MyStr & "<IMG SRC=改成你自己的图片存放的相对目录\" & Mid(sCounter, i, 1) & ".gif>" '如有图片,可用此语句调用
    Next
    Digital = MyStr
  End Function

  Function count_show  '读取计数函数
  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) '调用显示函数
  set fs=nothing
  End Function

%>

  然后新建一个count.txt(必须和count.asp同一级目录),打开这个文件后在里面输入任意数字(别太狠啦),然后在需要显示计数器的那个页面顶部加入

<!--#include file="count.asp"-->

最后在需要显示计数器的地方加上代码

<%=count_show%>

就OK了。
本文标签: computuer  
本文Url: http://www.918x.cn/post/198.html (出自: 黑暗天堂)
我要引用: 点击这里获取该日志的TrackBack引用地址

相关文章:

196. ARP欺骗详细介绍与安全防范  (2007-5-13 12:25:48)

184. Microsoft 漏洞MS07-027|最新漏洞利用|最新漏洞补丁  (2007-5-10 8:14:50)

178. 电子书籍制作|精美电子书|电子书教程|  (2007-5-6 10:13:58)

177. 最新版的挖掘鸡,希望大家能能挖到好的QQ号  (2007-5-4 18:7:59)

176. 最新商贸通漏洞利用|挂马|入侵  (2007-5-4 17:51:19)

1 Comments

一剑
学习一下,受用拉~~

Write a comment ?