Results 1 to 4 of 4

Thread: Hit counter that increments per session

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    7

    Hit counter that increments per session

    Can anyone please help me with this trying to make a session counter that but right now its incrementing at the start then increments again when i eather refresh or begin a new session but only increments again one time.
    Thanks for your time and help!

    This is my code so far.

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

    End Sub

    Const INCREMENT_COUNT = 0
    Const DECREMENT_COUNT = 1
    Const RESET_COUNT = 2

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)

    Call MakeCount(INCREMENT_COUNT)

    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)

    Call MakeCount(DECREMENT_COUNT)

    End Sub

    Sub MakeCount(ByVal iCountType)
    On Error Resume Next
    Select Case iCountType
    Case RESET_COUNT
    Application.Lock()
    Application("Count") = 0
    Application.UnLock()
    Case INCREMENT_COUNT
    Application.Lock()
    Application("Count") = Application("Count") + 2
    Application.UnLock()
    Case DECREMENT_COUNT
    'If Application("Count") > 0 Then
    Application.Lock()
    Application("Count") = Application("Count") - 1
    Application.UnLock()
    'End If
    End Select
    End Sub
    Last edited by IloveCaffeine; Aug 4th, 2005 at 05:25 PM.

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Hit counter that increments per session

    Use the Session_OnStart() method in the global.asax file. It is only called at the start of a Session. You could add code here to add one to a value held somewhere.

    Let me know if you need more help.

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    7

    Re: Hit counter that increments per session

    Still need some help please

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: Hit counter that increments per session

    Add a Class Module to your project with the following inside:
    VB Code:
    1. Public Class Scalars
    2.     Public Shared CurrentUsers As Integer
    3. End Class

    From your Global.asax file then use:
    VB Code:
    1. Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    2.         Scalars.CurrentUsers = Scalars.CurrentUsers + 1
    3.     End Sub
    4.  
    5.     Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
    6.         Scalars.CurrentUsers = Scalars.CurrentUsers - 1
    7.     End Sub

    From anywhere in your code you can find out how many users you have on your site by using:
    VB Code:
    1. Scalars.CurrentUsers
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width