请帮小弟解释一下这段程序

来源:百度知道 编辑:UC知道 时间:2024/05/23 16:13:21
Sub IncrementCounter()

Set fs = Server.CreateObject("Scripting.FileSystemObject")
counter_file = Server.MapPath("counter.txt")

Set txt = fs.OpenTextFile( counter_file )
Application("counter") = txt.ReadLine
txt.Close

Application("counter") = Application("counter") + 1

Set txt = fs.CreateTextFile( counter_file, True )
txt.WriteLine(Application("counter"))
txt.Close
End Sub
asp语言

是一个用txt做的访问统计

你应该注明是什么语言。

这是基于fso的一个网站计数器:
Sub IncrementCounter()
'创建fs文件对象
Set fs = Server.CreateObject("Scripting.FileSystemObject")
'获取counter.txt在服务器上的地址
counter_file = Server.MapPath("counter.txt")

'打开counter.txt文件
Set txt = fs.OpenTextFile( counter_file )
'读出数据并保存于Application变量counter中
Application("counter") = txt.ReadLine
'关闭counter.txt文件
txt.Close

'变量counter加1
Application("counter") = Application("counter") + 1

'再次打开counter.txt文件
Set txt = fs.CreateTextFile( counter_file, True )
'Application变量counter值写入文件
txt.WriteLine(Application("counter"))
'文件关闭
txt.Close
End Sub