PDA

View Full Version : Counter Problems


yokelrobin
08-30-2002, 09:50 AM
Can anyone see anything wrong with the following code:

<%@language=VBScript%>
<%on error resume next
fp = Server.MapPath("aspcount.txt")
Set fs = CreateObject("Scripting.FileSystemObject")
if fs.FileExists(fp) then
Set a = fs.OpenTextFile(fp)
ct = Clng(a.ReadLine)
a.close
else
ct=0
end if

if Session("ct") = "" then
Session("ct") = ct
ct = ct + 1

Set a = fs.CreateTextFile(fp, True)
a.WriteLine(ct)
a.close
end if

'Response.Write ct
%>

The file aspcount.txt is online, and in the same directory.

It just doesn't seem to work every time.

Anything obvious?

Thanks :) yok

Mhtml
08-30-2002, 11:52 AM
can't see the prob...but you are right, it doesn't increament every time.

this is how I'd do it.


<%
Set fs = CreateObject("Scripting.FileSystemObject")
TxtFile=server.mappath("aspcount.txt")
on error resume next
Set a = fs.OpenTextFile(TxtFile)
Count = Clng(a.ReadLine)
Count = Count + 1
a.close
if error then
hits = 1
end if

Set a = fs.CreateTextFile(TxtFile,True)
a.WriteLine(Count)
a.Close
%>

You are visitor <% =Count %>



you might want to check my coding.

yokelrobin
09-02-2002, 11:24 AM
Thanks for that :)