<%
'Dimension the variables
Dim txtFileObj ' As a file object
Dim objFSO ' As a FileSystemObject
Dim filePath ' As a logical path to the file
Dim TextStreamObj ' As a text stream object
Dim longIntCount ' As a long integer count variable
'Define constants
Const fileName = "asp_count.txt" 'file to read & write to
' Create a filesystem object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"
'Map the logical path to the physical path
filePath = Server.MapPath(fileName)
'Initialise the File Object with the path and name of the text file
Set txtFileObj = objFSO.GetFile(filePath)
'Create a TextStream Object to read, create, and write to the text file
Set TextStreamObj = txtFileObj.OpenAsTextStream
'Read in the number from the text file, convert it to long integer data type
'and save it in a variable.
longIntCount = CLng(TextStreamObj.ReadAll)
'Increment the count variable
longIntCount = longIntCount + 1
'Overwrite the original text file with a new counter file
Set TextStreamObj = objFSO.CreateTextFile(filepath)
'Write the new number into the counter file
TextStreamObj.Write CStr(longIntCount)
'Release server resources
Set objFSO = Nothing
Set TextStreamObj = Nothing
Set txtFileObj = Nothing
Response.Write("<br>The count is " & longIntCount)
%>
<br>
This file is read by another <A href="File Reader.asp">page</a> too!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.