• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

计数器代码[转]

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 20次 | 进入软件测试论坛讨论

领测软件测试网 最近许多网友在讨论计数器的问题,偶尔看到一篇文章,贴出来以解大家燃眉之急

一下代码贴在第一页即可
<%
‘’ Declare our vaiables
Dim objFSO, objCountFile ‘’ object vars for FSO and File
Dim strCountFileName ‘’ filename of count text file
Dim iCount ‘’ count variable
Dim bUseImages ‘’ boolean whether or not to use images
Dim I ‘’ standard looping var


‘’ Determine whether we use images or plain text
‘’ You could just set this to True or False instead
bUseImages = CBool(Request.QueryString("images"))

‘’ Compute our count file‘’s filename
‘’ This is based on the file from which you call count.asp
‘’ It basically takes that name and appends a .cnt so I don‘’t
‘’ accidently overwrite any files. If for some reason you have
‘’ a file named script_name.asp.cnt then change this or watch out!
strCountFileName = Server.MapPath(Request.ServerVariables("SCRIPT_NAME") & ".cnt")


‘’ Create FileSystemObject to deal with file access
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

‘’ Open the file as a text stream (1 = ForReading, True = Create)
Set objCountFile = objFSO.OpenTextFile(strCountFileName, 1, True)

‘’ Read the current count from the file
If Not objCountFile.AtEndOfStream Then
‘’ Set value to contents of the file
iCount = CLng(objCountFile.ReadAll)
Else
‘’ If no file exists or it‘’s empty start at 0
iCount = 0
End If

‘’ Close the file and destroy the object
objCountFile.Close
Set objCountFile = Nothing


‘’ Increment the count
iCount = iCount + 1


‘’ Overwrite existing file and get a text stream to new one
Set objCountFile = objFSO.CreateTextFile(strCountFileName, True)

‘’ Write updated count
objCountFile.Write iCount

‘’ Close the file and destroy the object
objCountFile.Close
Set objCountFile = Nothing


‘’ Destroy the FSO object
Set objFSO = Nothing


‘’ We‘’re all done with the hard part
‘’ All that‘’s left is to display the results
If bUseImages Then
‘’ Loop through the count integer showing each digit
‘’ You can grab the images one at a time or get the zip
‘’ http://www.asp101.com/samples/download/counter_imgs.zip
For I = 1 to Len(iCount)
‘’ Output the IMG tag using the right digit
Response.Write "<IMG SRC=""./images/digit_"
Response.Write Mid(iCount, I, 1)
Response.Write ".gif"" ALT="""
Response.Write Mid(iCount, I, 1)
Response.Write """ WIDTH=""20"" HEIGHT=""27"">"
Next ‘’I
Else
‘’ No image wanted just show the variable
Response.Write iCount
End If
%>

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网