470,581 Members | 2,427 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,581 developers. It's quick & easy.

Custom Hit Counter

I decide to put a custom Hit Counter on my page (below). Then I won't be
reliant on the standard FrontPage one which uses webbots.

It is called by
<b>Hit Counter: </b><!--#include file="_fpclass/hit_count.inc"-->
The code it includes is below.

OK, it works - sort of.

If I go to Guestbook and then return via the Home button, the counter
increases by 3, not 1.

I can't see why this is happenning.

After returning, a refresh increases it by 2, then another refresh increases
it by 1 ??

I know that many say "Don't use them - it is a sign of an amateur", but I
would at least like to get it working even if I later decide not to use it.

I have thought to make it a conditional include, i.e. if document.referrer
is blank. Is that possible?

'Dimension variables
Dim fsoObject 'File System Object
Dim tsObject 'Text Stream Object
Dim filObject 'File Object
Dim lngVisitorNumber 'Holds the visitor number
Dim intWriteDigitLoopCount 'Loop counter to display the graphical hit count
Dim cntDigit 'Holds the digit displayed in the counter

'Create a File System Object variable
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")

'Initialise a File Object with the path and name of text file to open
Set filObject = fsoObject.GetFile(Server.MapPath("_private/index.asp.cnt"))

'Open the visitor counter text file
Set tsObject = filObject.OpenAsTextStream

'Read in the visitor number from the visitor counter file
lngVisitorNumber = CLng(tsObject.ReadAll)

'Increment the visitor counter number by 1
lngVisitorNumber = lngVisitorNumber + 1

'Create a new visitor counter text file over writing the previous one
Set tsObject =

'Write the new visitor number to the text file
tsObject.Write CStr(lngVisitorNumber)

'Reset server objects
Set fsoObject = Nothing
Set tsObject = Nothing
Set filObject = Nothing

'Display the hit count as text
' Response.Write(lngVisitorNumber)

'Loop to display graphical digits
For intWriteDigitLoopCount = 1 to Len(lngVisitorNumber)
' Display the graphical hit count
cntDigit = Mid(lngVisitorNumber, intWriteDigitLoopCount, 1)
Response.Write("<img src=""counter_images/")
Response.Write(cntDigit & ".gif""")
Response.Write("alt=""" & cntDigit & """>")

Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/

Nov 25 '06 #1
0 1732

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Navin Mishra | last post: by
4 posts views Thread by WEG | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.