87,997
社区成员




<%
'Option Explicit
'变量定义
Dim fileName, fs, txt, Content, counterLenth, displayMode
'属性设置
counterLenth=0 '设置显示数据的最小长度,如果小于实际长度则以实际长度为准
displayMode =2 '设置显示模式,1为文字,2为图片
fileName=Server.MapPath("count.txt")
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'初始化
Function Init()
'检查文件是否存在,不存在则创建,并写入0
If Not fs.FileExists(fileName) Then
fs.CreateTextFile fileName,True,True
Set txt=fs.OpenTextFile(fileName,2,True)
txt.Write 0
txt.close()
Set txt=Nothing
End If
'缓存为空,则读取文本数据
Set txt=fs.OpenTextFile(fileName,1,1)
If txt.AtEndOfStream Then
Application("Counter")=0 '如果文件中没有数据,则初始化Application("Counter")的值(为了容错)
Else
Application("Counter")=txt.ReadLine
End If
txt.close()
Set txt=Nothing
Application.Lock '利用Application特性防止并发写入
Randomize
Application("Counter") = Application("Counter") + Int(((9-5+1) * Rnd) + 5)
SaveNum(Application("Counter")) '写入新数据
Application.UnLock
End Function
'显示计数函数
Function ReadNum()
Init()
ReadNum=PrintNumber(Application("Counter")) '调用显示方式函数
End Function
'保存数据函数
Function SaveNum(Content)
Set txt=fs.OpenTextFile(fileName,2,True)
txt.Write Content
txt.Close
Set txt = Nothing
End Function
'显示方式函数
Function PrintNumber(x)
Dim i,MyStr,sCounter
sCounter = Clng(x)
For i = 1 To counterLenth - Len(sCounter)
If displayMode=1 Then
MyStr = MyStr & "0"
Else
MyStr = MyStr & "<IMG SRC=\0.gif>" '如有图片,可调用此语句
End If
Next
For i = 1 To Len(sCounter)
If displayMode=1 Then
MyStr = MyStr & Mid(sCounter, i, 1)
Else
MyStr = MyStr & "<IMG SRC=改成你自己的图片存放的相对目录\" & Mid(sCounter, i, 1) & ".gif>" '如有图片,可调用此语句
End If
Next
PrintNumber = MyStr
End Function
%>