Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counter in ASP?

Status
Not open for further replies.

chris77

Technical User
May 6, 2003
5
DE
I want to add a counter to my home page. I was wondering if some one could guide me through the process, if it is even possible to use ASP as a counter source. I'm a rookie when it come to using ASP. So I would greatly appreciate all the help I can get..

--Christopher
 
this is about as basic as it gets for a asp counter. you use the global.asa in this "very simple"
<SCRIPT LANGUAGE=&quot;VBScript&quot; RUNAT=&quot;Server&quot;>
Option Explicit

Sub Application_OnStart
On Error Resume Next
Dim ObjCounter
Dim strCounter

strCounter = &quot;ProjectName&quot;
Application(&quot;CounterName&quot;) = strCounter

Set ObjCounter = Server.CreateObject(&quot;MSWC.Counters&quot;)
If (Err <> 0) Then
Application(&quot;IsErr&quot; ) = Err.Number
Else
Call Counters.Set(HitsCounter, 1 )
Set Application(&quot;MSCounters&quot;) = ObjCounter
Application(&quot;IsErr&quot;) = 0
End If

Err.Clear
End Sub


Sub Application_OnEnd
On Error Resume Next
Application(&quot;IsErr&quot;) = Nothing
Application(&quot;MSCounters&quot;) = Nothing
End Sub


Sub Session_OnStart
Err = 0
End Sub


Sub Session_OnEnd
Err = 0
End Sub

</SCRIPT>

to write it to the page do
<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>

<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
</HEAD>
<BODY>
<h2>Demo of the ASP Counter Component</h2>

<%
On Error Resume Next

Dim ObjCntr
Dim nCount, nErr
Dim strName
strName= Application(&quot;CounterName&quot;)

Set ObjCntr = Application(&quot;MSCounters&quot;)
nCount = ObjCntr.Increment(strName)
nErr = Application(&quot;IsErr&quot;)


If (Err <> 0 AND nErr <>0) then
Response.Write (&quot;<P>Error: Could not get the instance of the Counters Object.<br> Error Code:&quot; + CStr(nErr) )
Else
Response.Write (&quot;<h4><P>There have been&quot; + CStr(nCount) + &quot; visits to this Web page.&quot;)
End If
%>

</BODY>
</HTML>
[bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top