10.25.05

“Share” in classes – Visitors counter

Posted in Uncategorized at 2:04 am by aspnet

In general, it is good practice to always explicitly define the scope of methods and variables to avoid confusion. As with shared methods, we can scope the shared variable as required. Where Shared methods are Public by default, Shared variables are Private by default.

Public Class MyCounter
  Private Shared mintCount As Integer
  Public Sub New()
    mintCount += 1
  End Sub
  Public ReadOnly Property Count() As Integer
    Get
      Return mintCount
    End Get
  End Property
End Class

The above function can be used to calculate the numbers of visitors that visit your site.

To call it,

Dim obj As MyCounter 
obj = New MyCounter()

And you get your own simple visitors counter!

Leave a Comment