Whistling in the wind

Discussion in 'ASP General' started by Trevor L., Dec 31, 2006.

  1. Trevor L.

    Trevor L. Guest

    The subject says it, I think.

    I have a hit counter on my page below
    The code is
    <b>Hit Counter: </b><!--#include file='_fpclass/hit_count.inc'-->
    where '_fpclass/hit_count.inc' is

    <%
    'Dimension variables
    Dim fsoObject 'File System Object
    Dim filObject 'File Object
    Dim tsObject 'Text Stream 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 =
    fsoObject.CreateTextFile(Server.MapPath("_private/index.asp.cnt"))

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

    'Reset server objects
    Set fsoObject = Nothing
    Set filObject = Nothing
    Set tsObject = 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 & """>")
    Next
    %>

    What I am wondering is:
    Why does the count increment by 3 every time I visit the Guestbook and then
    return to the Home Page ?
    The Guestbook button is
    <a href="guestbook.asp" target="_self">
    <img src="images/display/guestbook-icon1.gif" alt="Guestbook" height="40"
    /><br />
    Guestbook</a>

    Even clicking Home increments it by 2
    The Home button is
    <a href="index.asp" target="_self">
    <img src="images/display/sitehome.gif" alt="Home" /><br />
    Home</a>

    Visiting my other web site and then returning does the same thing
    (increments it by 2).
    This button is
    <a href="http://tandcl.homemail.com.au">
    <img src="images/display/trevor-and-carole.gif" alt="T&C" /><br />
    Trevor and Carole's<br />Home Page</a>

    Is there some way I can only increment the counter when the site
    (http://trevorl.mvps.org/) is visited for the first time?
    And going to somewhere else and then returning will not increment it?

    --
    Cheers,
    Trevor L.
    [ Microsoft MVP - FrontPage ]
    MVPS Website: http://trevorl.mvps.org/
    ----------------------------------------
     
    Trevor L., Dec 31, 2006
    #1
    1. Advertising

  2. Trevor L.

    Bob Lehmann Guest

    Put the code that increments the count in the Session_OnStart sub in
    global.asa.

    Also, you should look into using Application.Lock while writing to your text
    file.

    Bob Lehmann

    "Trevor L." <Trevor_L.@Canberra> wrote in message
    news:...
    > The subject says it, I think.
    >
    > I have a hit counter on my page below
    > The code is
    > <b>Hit Counter: </b><!--#include file='_fpclass/hit_count.inc'-->
    > where '_fpclass/hit_count.inc' is
    >
    > <%
    > 'Dimension variables
    > Dim fsoObject 'File System Object
    > Dim filObject 'File Object
    > Dim tsObject 'Text Stream 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 =
    > fsoObject.CreateTextFile(Server.MapPath("_private/index.asp.cnt"))
    >
    > 'Write the new visitor number to the text file
    > tsObject.Write CStr(lngVisitorNumber)
    >
    > 'Reset server objects
    > Set fsoObject = Nothing
    > Set filObject = Nothing
    > Set tsObject = 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 & """>")
    > Next
    > %>
    >
    > What I am wondering is:
    > Why does the count increment by 3 every time I visit the Guestbook and

    then
    > return to the Home Page ?
    > The Guestbook button is
    > <a href="guestbook.asp" target="_self">
    > <img src="images/display/guestbook-icon1.gif" alt="Guestbook"

    height="40"
    > /><br />
    > Guestbook</a>
    >
    > Even clicking Home increments it by 2
    > The Home button is
    > <a href="index.asp" target="_self">
    > <img src="images/display/sitehome.gif" alt="Home" /><br />
    > Home</a>
    >
    > Visiting my other web site and then returning does the same thing
    > (increments it by 2).
    > This button is
    > <a href="http://tandcl.homemail.com.au">
    > <img src="images/display/trevor-and-carole.gif" alt="T&C" /><br />
    > Trevor and Carole's<br />Home Page</a>
    >
    > Is there some way I can only increment the counter when the site
    > (http://trevorl.mvps.org/) is visited for the first time?
    > And going to somewhere else and then returning will not increment it?
    >
    > --
    > Cheers,
    > Trevor L.
    > [ Microsoft MVP - FrontPage ]
    > MVPS Website: http://trevorl.mvps.org/
    > ----------------------------------------
    >
     
    Bob Lehmann, Dec 31, 2006
    #2
    1. Advertising

  3. Trevor L.

    Trevor L. Guest

    Bob Lehmann wrote:
    > Put the code that increments the count in the Session_OnStart sub in
    > global.asa.
    >
    > Also, you should look into using Application.Lock while writing to
    > your text file.
    >
    > Bob Lehmann


    Thanks, Bob

    This appears to have worked. However, I tried this once before and the next
    time I went into the site, the Hit Counter wasn't even displaying.
    (That is, if I recall correctly, this code" <b>Hit Counter:
    </b><!--#include file='_fpclass/hit_count.inc'--><br /> didn't even display
    *Hit Counter*

    Maybe I did something wrong last time, so I think I will wait for the time
    out period (15 minutes ?) and try again with my fingers crossed

    --
    Cheers,
    Trevor L.
    [ Microsoft MVP - FrontPage ]
    MVPS Website: http://trevorl.mvps.org/
    ----------------------------------------
     
    Trevor L., Jan 1, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kashumoto_tokugawa
    Replies:
    1
    Views:
    1,703
  2. Mathematician
    Replies:
    0
    Views:
    568
    Mathematician
    Dec 24, 2006
  3. Caleb

    Wind Resistance

    Caleb, Apr 10, 2007, in forum: Java
    Replies:
    7
    Views:
    568
    Christian
    Apr 10, 2007
  4. Robbie Hatley

    How do I wind this into a nested loop?

    Robbie Hatley, Feb 29, 2008, in forum: C Programming
    Replies:
    7
    Views:
    365
    William Pursell
    Mar 1, 2008
Loading...

Share This Page