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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hit counter code won't write text file

Status
Not open for further replies.

49er

Programmer
Aug 24, 2000
38
US
I am trying to have a hit counter for my website but the following code will not write the text file to hold the counter. I am fairly new to this so I am shooting from the hip and any help would be greatly appreciated. This was originally a frontpage web (I don't know if this could possibly have an affect or not). I have full permissions to the 'counter' directory.


Code:
Sub Application_OnStart
   Dim fsVisitors   'FileSystemObject object
   Dim fileVisitors 'TextStream object
 
    Set fsVisitors = Server.CreateObject       ("Scripting.FileSystemObject")
    Set fileVisitors = fsVisitors.OpenTextFile("C:\InetPub\[URL unfurl="true"]wwwroot\counter\IntraHome.txt")[/URL]
    
    If err.number <> 0 Then
		Set fileVisitors = fsVisitors.CreateTextFile(&quot;C:\InetPub\[URL unfurl="true"]wwwroot\counter\IntraHome.txt&quot;)[/URL]
		err.clear
	End If
    
    'Read counter value from text file
    Application(&quot;visitors&quot;) = fileVisitors.ReadLine
    fileVisitors.Close
end sub
Sub Session_OnStart
    Application.Lock
    Application(&quot;visitors&quot;) = Application(&quot;visitors&quot;) + 1
    Application.Unlock
end sub
Sub Application_OnEnd
    Dim fsVisitors   'FileSystemObject object
    Dim fileVisitors 'TextStream object
 
    Set fsVisitors = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
    Set fileVisitors = fsVisitors.CreateTextFile(&quot;C:\InetPub\[URL unfurl="true"]wwwroot\counter\IntraHome.txt&quot;,[/URL] True)
    'Write counter value to text file
    fileVisitors.Writeline(Application(&quot;visitors&quot;))
    fileVisitors.Close
End Sub
 
i hope IntraHome.txt exists? If it doesn't it will produce an error like:

Server object error 'ASP 0177 : 800a0035'
Server.CreateObject Failed
/tsnl-ict/test.asp, line 8

Server.CreateObject will not create a new file.
[i copied your source in a test.asp and it runs fine.
I changed the folder, because my project is not called 'counter'.]
br
Gerard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top