...

View Full Version : Getting the Counter Component Working



Carl
10-04-2002, 12:01 AM
I've been trying to get the counter component working about two weeks now and everything has failed. I don't get an error, it just shows a 0 value, infact not even a zero. Nothing,

Heres my code

Global.ASA
Sub Application_OnStart
Application.Lock
Application("currentUser") = 0
Application("allUser") = 0
Application.UnLock
End Sub

Sub Session_OnStart
Application.Lock
Application("currentUser") = Application("currentUser") + 1
Application("allUser") = Application("allUser") +1
Application.UnLock
End Sub

Sub Session_OnEnd
Application("currentUser") = Application("currentUser") - 1
End Sub

Page
Response.Write(Application("currentUser"))


Thanks,

Carl

whammy
10-04-2002, 02:49 AM
Offhand, I don't see any reason why that shouldn't work...

except the currentuser variable does nothing that the alluser variable doesn't do... so why do you have it in there?...

Is the global.asa in the same root directory (or parent root directory) as the page that's requesting the application variable?

Carl
10-04-2002, 02:58 AM
Well I put allusers in there because it wasn't working, plus my book has it in there in the code, so I assume its correct.

I have the global.asa in the WebRoot directory and the page I access it is in a subfolder.

Do you happen to have to correct working code for this? I'm getting really frustrated with this :)

Carl

whammy
10-04-2002, 03:09 AM
I use application variables every day, so I'm assuming you just overlooked something, or that your book left something out, or that your server isn't set up correctly? OK, I'm going to stop assuming this point and hope you have the code.

Can you post the code for the global.asa AND the page that's requesting the application variable here?

Carl
10-04-2002, 03:14 AM
Well I already posted all of the Global.ASA file, so heres my code for the page.



<table cellpadding="0" cellspacing="0" border="0" bgcolor="black" width="95%" align="center" height="1"><tr><td>
<table width=100% cellspacing="1" height="1">
<tr>
<td class="title1">Board Name</td>
<td class="title1" width="120" align="center">Last Post</td>
<td class="title1" width="120" align="center">Posts</td>
</tr>
<!-- Print Boards Here -->
<%
Set conn = Server.CreateObject("ADODB.Connection")
sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\\premfs5\sites\premium10\carlv\database\CBoards\forums.mdb;" & _
"Persist Security Info=False"
conn.Open(sConnection)

sqlCat = "SELECT * FROM Cat ORDER BY theorder"
Set recCat = conn.Execute(sqlCat)

if Session("loggedin") = "yes" Then
sqlUser = "SELECT username,thelevel FROM Users WHERE username='"&Session("CBUsername")&"'"
set recUser = conn.Execute(sqlUser)
thelevel = recUser("thelevel")
else
thelevel = "1"
end if

Do While Not recCat.EOF
if recCat("Hidden") = "y" AND thelevel = "2" Or recCat("Hidden") = "n" Then

sqlBoard = "SELECT * FROM Boards WHERE CatID='"&recCat("id")&"' ORDER BY theorder"
Set recBoard = conn.Execute(sqlBoard)

Response.Write("<tr>")
Response.Write("<td class='color1' colspan='4'><b>"&recCat("CatTitle")&"</b></td>")
Response.Write("</tr>")

Do While Not recBoard.EOF

Response.Write("<tr>")
Response.Write("<td class='thecolor2'><b><a href='index.asp?page=showboard&boardid="&recBoard("id")&"'>"&recBoard("BoardName")&"</a>")
if recBoard("Locked") = "y" Then
Response.Write(" - <i>Locked</i>")
end if
Response.Write("</b><br><i>"&recBoard("BoardDiscription")&"</i></td>")
if recBoard("LastPostID") = "0" OR recBoard("LastPostUser") = "" Then
Response.Write("<td class='color1' align=center>Never</td>")
else
Response.Write("<td class='color1' align=center>by, "&recBoard("LastPostUser")&"</td>")
end if
sqlTP = "SELECT COUNT(*) AS totalpost FROM Topics WHERE BoardID = "&recBoard("id")&""
Set recTP = conn.Execute(sqlTP)
sqlTR = "SELECT COUNT(*) AS totalreply FROM Replies WHERE BoardID = "&recBoard("id")&""
Set recTR = conn.Execute(sqlTR)
thetotal = recTP("totalpost") + recTR("totalreply")
Response.Write("<td class='thecolor2' align=center>"&thetotal&"</td>")
Response.Write("</tr>")

recBoard.MoveNext
Loop

recCat.MoveNext

else
recCat.MoveNext
end if
Loop

Set recCat = Nothing
Set recBoard = Nothing
%>
<!-- End Print Boards -->
<tr>

<td colspan="4" class="color1"><b><a href="index.asp?page=stats">Current Active Users: <%Response.Write(Application("currentUser"))%></a></b></td>
</tr>
</table>
</td></tr></table>


Carl

whammy
10-04-2002, 03:24 AM
Hmm.. that should work (assuming I didn't miss something)... if I were you I'd make a test .asp page (in the same directory of course), that only contains this line:

<% = Application("currentUser") %>

To debug it...

That would be my first step.

P.S.

<% = variable %>

is a shortcut to

<% Response.Write(variable) %>

Carl
10-04-2002, 03:28 AM
Just a blank page (www.carlsoft.net/test.asp)

Carl

whammy
10-04-2002, 03:30 AM
Ok, I just went there... that proves that your application variable is not being set! :D

Now comes the second stage... why?

Carl
10-04-2002, 03:39 AM
Oh I just dipise guessing games :D

Is that because of the server? I'm using Brinkster.

Carl

whammy
10-04-2002, 03:43 AM
Hmm... I'm not trying to make guessing games, that's what debugging is all about... it's up to you to figure out by trial and error what's wrong, by making sure that everything that SHOULD work does! :D

As for brinkster, I haven't used application variables there, but I'd definitely search their documentation for the global.asa file to see if they have any restrictions on it... I have a site there but it pretty much uses Access 2000 databases or SQL Server...

Carl
10-04-2002, 04:00 AM
Global.ASA files are support by brinkster so no problem there.

I'll try playing around with the varibles.

Thanks,
Carl.

anandc
10-06-2002, 08:45 PM
Hi

I have used Counter Object with a text file without editing the Global.asa file. I fyou want to see it please visit at

http://www.bhandaradist.com

if you do need the code i will.

Anand

Carl
10-06-2002, 10:44 PM
Thanks, but I don't see how that shows how many users are online. I can get the page counter working without a problem.

Thanks though,

carl

whammy
10-06-2002, 11:25 PM
...:eek:

Looking through your code again, I noticed something... you left out the script tags:

<script language="vbscript" runat="server">

</script>

Which are needed in order for the global.asa file to understand what you're doing.

Carl
10-06-2002, 11:30 PM
But you told me to remove it. I'll put it back.

It worked! :thumbsup: :thumbsup: :thumbsup: :)

Its been three weeks since I've been trying to get this working. Thanks :)

Carl
10-06-2002, 11:41 PM
Wait, no, now its a counter again. Darn, How can I display the current active users?

Carl

whammy
10-07-2002, 01:50 AM
You're using the wrong variable... instead of Application("currentUser")

use Application("allUser")

since currentuser is only counting YOU with the session variable

As a matter of fact, that "currentUser" variable is rather useless... since you know you're on the site! I'd just do what w3schools.com does:



<script language="vbscript" runat="server">
Sub Application_OnStart
Application("visitors")=0
End Sub
Sub Session_OnStart
Application.Lock
Application("visitors")=Application("visitors")+1
Application.UnLock
End Sub
Sub Session_OnEnd
Application.Lock
Application("visitors")=Application("visitors")-1
Application.UnLock
End Sub
</script>


:)

Carl
10-07-2002, 02:09 AM
Thanks :)

Carl



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum