<% 'Reading from the file Const ForReading = 1 ' our variables Dim objFSO , objTextStream , strText , strFileName, Stuff, myFSO, WriteStuff, str 'Path to our text file strFileName = Server.MapPath("counter.txt") 'create an instance of the FileSystemObject Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 'open our text file Set objTextStream = objFSO.OpenTextFile(strFileName , ForReading , False) If not objTextStream.AtEndOfStream Then Do While not objTextStream.AtEndOfStream 'read in our text one line at a time and display it strText = objTextStream.ReadLine Loop End If 'Incrementing the counter by 1 strText =strText + 1 'Response.Write strText & "
" objTextStream.Close 'good practice to setobject variables to nothing Set objFSO = Nothing Set objTextStream = Nothing 'Writing to file 'this line creates an instance of the File Scripting Object named myFSO Set myFSO = CreateObject("Scripting.FileSystemObject") 'this line opens the file, notice the 2, it will cause the script to write to the file (overwriting existing text) Set WriteStuff = myFSO.OpenTextFile(strFileName, 2, True) 'this line actually writes STUFF from above to the file WriteStuff.WriteLine(strText) ''this line closes the file WriteStuff.Close 'this line destroys the instance of the File Scripting Object named WriteStuff SET WriteStuff = NOTHING 'this line destroys the instance of the File Scripting Object named myFSO SET myFSO = NOTHING str="document.write(""This web site has received " & strText & " visitors."");" Response.Write str %>