落伍者站长论坛's Archiver

rxy258 发表于 2008-11-15 21:28

计数器代码溢出,请帮忙修改

网页调用了一个计数器代码,以前一切正常,今天突然网页不能显示,最后发现是计数器的问题,当页面点击数到32766时一切正常,再刷新下页面到32767时就不正常了,提示如下:
[quote]
[color=red]Microsoft VBScript 运行时错误 '800a0006' [/color][color=red]溢出: 'cint' [/color][color=red]\wwwroot\counter.asp, line 56[/color]
[color=black][/quote][/color]
[color=black][/color]
[color=black]计数器源代码如下,请求高手帮忙修改下,(红颜色处为第56行):[/color]
[color=#000000][quote][/color]
<%
    option explicit
dim fs,filename,txt,content,total,counter_lenth
counter_lenth=7  '设置显示数据的最小长度,如果小于实际长度则以实际长度为准
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 read_  '读取计数函数
set fs=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("count.txt")
    set txt=fs.opentextfile(filename,1,true)
total=txt.readline
[color=red]total=cint(total)[/color]
'response.write total
response.write Digital (total) '调用显示函数
set fs=nothing
  End Function
%>
[/quote]

rxy258 发表于 2008-11-15 21:51

或者谁给推荐个好点的计数器

会跳舞的大象 发表于 2008-11-15 22:13

total=cint(total)
改成
total=clng(total)

易木宁 发表于 2008-11-15 23:51

cint的最大值是32767

rxy258 发表于 2008-11-19 13:21

[quote]原帖由 [i]会跳舞的大象[/i] 于 2008-11-15 22:13 发表 [url=http://www.im286.com/redirect.php?goto=findpost&pid=31176422&ptid=3040732][img]http://www.im286.com/images/common/back.gif[/img][/url]
total=cint(total)
改成
total=clng(total) [/quote]
谢谢指点
现已恢复正常

[[i] 本帖最后由 rxy258 于 2008-11-19 13:43 编辑 [/i]]

fdgo 发表于 2008-11-19 15:25

:ohh:

itxiaozi 发表于 2008-11-19 18:52

长整形?

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.