If using ASP, it's about as easy to use an Access DB as it is to use a file, but okay...
We will say that the file format is this:
name : count
with each person on a separate line.
So the file might look like:
And anybody who has not submitted a form doesn't even appear in the file.
We will put the file into a directory named "data" that is under the root directory. We'll put the code in the root directory. We will assume that you will invoke the page by hitting a URL of the form http://www.yoursite.com/countDownloads.asp?name=John+Doe
Yeah, would actually be slightly shorter to use a database.
name = Request("name")
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set infile = FSO.OpenTextFile( Server.MapPath("data/downloads.txt") )
lines = infile.ReadAll ' reads entire text file into memory
lines = Split( lines, vbNewLine ) ' break text into an array of lines
done = False
For i = 0 To UBound(lines)
temp = Split( lines(i), ":" )
If LCase(name) = LCase(temp(0)) Then
' aha! this person already in the file...change his/her count:
temp(1) = CINT( temp(1) ) + 1
' put the line back in place:
lines(i) = Join( temp, ":" )
done = True
Exit For ' and we are done
If Not done Then
' that name not found in the file, so add a line:
ReDim Preserve lines( UBound(lines) + 1 ) ' bump size by 1
lines( UBound(lines) ) = name & ":1" ' give this person one download
' true says overwrite existing file:
Set outfile = FSO.CreateTextFile( Server.MapPath("data/downloads.txt"), True )
outfile.Write Join( lines, vbNewLine ) ' write out all the lines
outfile.WriteLine "" ' with a terminating line break