Adding Counter to your Webpage
Description from: http://www.chilisoft.com/caspdoc/
The Counter component creates a Counters object that can create, store, increment, and retrieve any number of individual counters.
A counter is a persistent value that contains an integer. You can manipulate a counter with the Get, Increment, Set, and Remove methods of the Counters object. Once you create the counter, it persists until you remove it.
Counters do not automatically increment on an event like a page hit. You must manually set or increment counters using the Set and Increment methods.
Counters are not limited in scope. Once you create a counter, any page on your site can retrieve or manipulate its value. For example, if you increment and display a counter named hits in a page called Page1.asp, and you increment hits in another page called Page2.asp, both pages will increment the same counter. If you hit Page1.asp, and increment hits to 34, hitting Page2.asp will increment hits to 35. The next time you hit Page1.asp, hits will increment to 36.
All counters are stored in a single text file, counters.txt.
Only create one Counters object in your site. This single Counters object can create any number of individual counters.
The control makes use of no registry settings.
The Counters Control is registered with the ProgId of "MSWC.Counters". Create the Counters object one time on your site by adding the following to the global.asa file:
<OBJECT>
RUNAT=Server
SCOPE=Application
ID=Counter
PROGID="MSWC.Counters">
</OBJECT>
This does not utilise any properties, but uses the following methods:
Method Details
The Get method takes the name of a counter and returns the current value of the counter. If the counter doesn't exist, the method creates it and sets it to 0.
Arguments:
| CounterName |
A string containing the name of the counter |
Example:
Display the value a counter with <%= Counters.Get(CounterName) %>. Assign the value of the counter to a variable with <% countervar = Counters.Get(CounterName) %>.
The following script displays the vote tally from a poll about favorite colors.
<%
If colornumber = "1" Then
Counters.Increment("greencounter")
Else
If colornumber = "2" Then
Counters.Increment("bluecounter")
Else
If colornumber = "0" Then
Counters.Increment("redcounter")
End If
End If
End If
%>
<P>Current vote tally:
<P>red: <% =Counters.Get("redcounter") %>
<P>green: <% = Counters.Get("greencounter") %>
<P>blue: <% = Counters.Get("bluecounter") %>
The Increment method takes the name of a counter, adds 1 to the current value of the counter, and returns the counter's new value. If the counter doesn't exist, the method creates it and sets its value to 1.
Arguments
| CounterName |
A string containing the name of the counter |
Example:
Increment the value of a counter with <% Counters.Increment(CounterName) %>. Increment and display the value of a counter with <%= Counters.Increment(CounterName) %>.
To retrieve the value of a counter, use Counters.Get. To set a counter to a specific value, use Counters.Set.
The following code implements a one-line page-hit counter.
There have been <%= Counters.Increment("hits") %> visits to this Webpage.
In this example, Counters.Increment increases the counter by one each time the client requests the page from the server.
The Remove method takes the name of a counter, removes the counter from the Counters object, and deletes the counter from the Counters.txt file.
Arguments:
| CounterName |
A string containing the name of the counter |
Example:
The following code removes the counter hitscounter from the counters.txt file.
<% Counters.Remove(hitscounter) %>
The Set method 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 doesn't exist, Counters.Set creates it and sets it to the value of the integer.
Arguments:
| CounterName |
A string containing the name of the counter |
| int |
The new integer value for CounterName |
Example:
The following code resets the hit counter pageHits to 0:
<% Counters.Set(pageHits, 0) %>
Content Linking
The NextLink object manages a list of URLs so that you can automatically generate a table of contents and/or navigational links.
The Content Linking component creates a Nextlink object that manages a list of URLs so that you can treat the pages in your Website like the pages in a book. You can use the Content Linking component to automatically generate and update tables of contents and navigational links to previous and subsequent Webpages. This is ideal for applications such as online newspapers and forum message listings.
The Content Linking component references a Content Linking List file that contains the list of the linked Webpages. This list is stored on the Web server and must be available on a web server virtual path.
The control makes use of no registry settings.
The Content Linking component is registered with the ProgId of "MSWC.NextLink". The following VBScript excerpt shows creating an instance of the control.
Set cLinker = Server.CreateObject( "MSWC.NextLink" )
The Content Linking component exposes the following properties and methods
There are no properties, however the methods are:
GetListCount
GetListIndex
GetNextDescription
GetNextURL
GetNthDescription
GetNthURL
GetPreviousDescription
GetPreviousURL
Method Details
The GetListCount method retrieves the total number of Webpages listed in the Content Linking List file.
Arguments:
| listURL |
The location of the Content Linking List file. |
Return Values:
This method returns an integer.
The GetListIndex method retrieves the index number of the current item in the Content Linking List file.
Arguments:
| listURL |
The location of the Content Linking List file. |
Return Values:
The GetListIndex method returns an integer index value specifying the current page's position on the file list. The index number of the first item is 1. The method returns 0 if the current page is not in the Content Linking List file.
The GetNextDescription method retrieves the text description of the next item in the Content Linking List file.
Arguments:
| listURL |
The location of the Content Linking List file. |
Return Values:
The GetNextDescription method returns an ASCII string describing the next item in the Content Linking List file. If the current page is not found in the list file, GetNextDescription returns the string description of the last page on the list.
The GetNextURL method retrieves the URL of the next item in the Content Linking List file.
Arguments:
| listURL |
The location of the Content Linking List file. |
Return Values
This method returns the URL of the next page specified in the Content Linking List file. If the current page is not specified in the Content Linking List file, GetNextURL returns the URL of the last page on the list.
Example:
The following example uses the GetNextURL method to embed a link to the next page in the Content Linking List file. The advantage of using GetNextURL is that when you change the order or number of the content pages, you only have to update the list in Content Linking List file and do not need to update the navigational links on each page.
<% Set NextLink = Server.CreateObject ("MSWC.NextLink") %>
<A HREF="<%= NextLink.GetNextURL ("/data/nextlink.txt") %>">Next Page </A>
The GetNthDescription method retrieves a text description of the Nth item in the Content Linking List file.
Arguments:
| listURL |
The location of the Content Linking List file. |
| index |
The index number of an item in the Content Linking List file |
Return Values:
This method returns a string.
The GetNthURL method returns the URL of the Nth item in the Content Linking List file.
Arguments:
| listURL |
The location of the Content Linking List file. |
| index |
The index number of an item in the Content Linking List file |
Return Values:
This method returns a string.
The GetPreviousDescription method retrieves a text description of the previous item in the Content Linking List file.
Arguments:
| listURL |
The location of the Content Linking List file. |
Return Values:
This method returns a string describing either the previous item in the Content Linking List file or, if the current page is not in the file, the first item on the list.
The GetPreviousURL method returns the URL of the previous item in the Content Linking List file.
Arguments:
| listURL |
The location of the Content Linking List file. |
Return Values:
This method returns a string containing the URL of the previous item in the Content Linking List file. If the current page is not specified in the Content Linking List file, GetPreviousURL returns the URL of the first page in the file.
General Example
The following example builds a table of contents.
<OL>
<%
Set NextLink = Server.CreateObject ("MSWC.NextLink")
count = NextLink.GetListCount ("/data/nextlink.txt")
I = 1
%>
<UL>
<% Do While (I <= count) %>
<LI><A HREF=" <%= NextLink.GetNthURL ("/data/nextlink.txt", I) %> ">
<%= NextLink.GetNthDescription ("/data/nextlink.txt", I) %> </A>
<%
I = (I + 1)
Loop
%>
</UL>
</OL>
The following script adds the next-page and previous-page buttons to an HTML file.
<%
Set NextLink = Server.CreateObject ("MSWC.NextLink")
If (NextLink.GetListIndex ("/data/nextlink.txt") > 1)
Then
%>
<A HREF=" <%= NextLink.GetPreviousURL ("/data/nextlink.txt") %> ">
Previous Page</A>
<% End If %>
<A HREF=" <%= NextLink.GetNextURL ("/data/nextlink.txt") %> ">Next Page</A>
The Content Linking List file contains one line of text for each URL in the list. Each line ends in a carriage return and each item on a line is separated by a TAB character.
Syntax
Web-page-URL [ text-description [ comment]]
Values
Web-page-URL:
The virtual or relative URL of the Webpage in the format filename or directory\filename. Absolute URLs, those that start with "http:", "//", or "\\", are not supported and will not be processed by methods such as GetNextURL and GetListIndex. When building your content path, you should ensure that no collisions or infinite loops can occur.
text-description:
A value containing text that describes Web-page-URL.
comment:
Explanatory text that is not processed by the component.
Example:
The following text file creates a list of URLs that can be used by the Content Linking component.
---NEXTLINK.TXT---
story1.htm Highlights From the Hockey Playoffs
story2.htm Congress Passes New Welfare Initiative
story3.htm Cider Recipes to Warm Long Winter Nights
story4.htm Winter Storm to bring more snow to East
story5.htm Reducing Stress on the Job
main.htm Return to the table of contents |