<%
CountFile = Server.MapPath("count.txt") '開啟檔案
set Object = Server.CreateObject("Scripting.FileSystemObject") '呼叫檔案處理元件
set file1= Object.OpenTextFile(CountFile, 1, false, false) '設定檔案為唯讀
counter = file1.ReadLine '讀取檔案
file1.Close '關閉檔案
if isempty(Session("connected")) then '紅色部份可管制計數器在重新整理不會增加
set Object = Server.CreateObject("Scripting.FileSystemObject") '呼叫檔案處理元件
set file1= Object.CreateTextFile (CountFile, true, false) '設定寫入時覆蓋原檔案
Application.lock '鎖定 Application 物件
counter= counter + 1 '將計數器加1
file1.WriteLine(counter) '將資料寫入檔案
Application.unlock '解鎖 Application 物件
file1.Close '關閉檔案
Session("connected") = true
end if
'response.write counter '完成計數器
'-----------------------------------------以下動作只是要將計數器前面補上0
response.write ""
count_len = len(counter) '計數器目前字數
count_full = 5 '設定計數器為五位數
for i=1 to count_full - count_len '補滿0
txt1 = "0" + txt1
next
do while count_len > 0 '計數器數字
txt2 = mid(counter, count_len, 1) + txt2
count_len = count_len - 1
loop
txt = txt1 + txt2 '加在一起
response.write txt '完成有補0的計數器
%>