This component creates a Counter object that can generate, store, increment, and retrieve any number of counters. A counter contains an integer that you can use with the Get, Increment, Set, and Remove methods of the Counters object. If a counter is created, it persists until you remove it. Counters do not get incremented automatically on an event like a page hit. They should be manually set or incremented using the Set and Increment methods.
Several pages on a specific site can retrieve or use the value of a single counter. For example, if you increment and display a counter named Clicks in a page called PAGE1.HTM, and you increment Clicks in another page called PAGE2.ASP, both pages will increment the same counter. If you hit page1.htm and increment Clicks to 3, hitting PAGE2.ASP will increment Clicks to 4. The next time you hit PAGE1.HTM, Clicks will increment to 5. All counters are stored in a single text file, COUNTER.TXT. This file should not be modified manually.
Creates, stores, increments, and retrieves any number of counters.
Returns the current value of the specified counter. If the counter does not exist, this method creates the counter and sets its value to 0.
object.Get( CounterName As String)
Long. Represents the current value of the counter.
For more details on displaying the values of a specific counter see Example.
Increments the specified hit count for the current Web page by 1. If the specified counter does not exist, it creates one by the specified name and sets its value to 1.
object.Increment( CounterName As String)
Long. Represents the current value of the counter.
For more details on incrementing a counter and displaying its values see Example.
Takes the name of a counter and an integer, sets the counter to the value of the integer, and returns the new value. If the counter does not exist, this method creates it and sets it to the value of the integer specified.
object.Set( CounterName As String Value As Integer)
None.
For more details on setting the counter to a new value see Example.
Removes the counter from the Counters object and deletes the counter from the COUNTER.TXT file.
object.Remove( CounterName As String)
None.
The following code file increments the counters "student", "teachers" and "parents" based on the given label value and displays the incremented values. It also gives the page visit count and removes the counter "student" from COUNTER.TXT file.
<% Set counters = Createobject("MSWC.Counters") %> <% Counters.Set("teacher",10) ’Set the count of teacher to 10 %> <% ’Increment the count of specified field by 1based on the input ’label value. If label = "1" Then Counters.Increment("Student") Else If label = "2" Then Counters.Increment("teacher") Else If label = "0" Then Counters.Increment("parent") End If End If End If %> <P> Current strength: <P> stu: <% =Counters.Get( "Student" ) ’Displays the latest count for specified fields. %> <P> teach: <% = Counters.Get( "teacher" ) %> <P> par: <% = Counters.Get( "parent" ) %> <% Counters.Remove("student") ’Deletes a counter from counter.txt file. %> <P> This web page has been viewed <%= Counters.Increment("hits") ’increments and displays the value of the counter%> times. </P>