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!

Voting

Status
Not open for further replies.

Hatsu

Programmer
Sep 25, 2003
2
GB
I have been trying for a week to do this, but no luck yet.

I have created a form that a user can vote on, which passes a number(1-5) to the asp page. I have made the the asp page recieve the value and now what I was hoping to do, was to use something like the case statement to select the path to right to and then rasie that textfile value by one.

However everything I have tried returns me a HTTP 500 - Internal server error.

I looked a few code snippets but none seem to work. I have thought manage to write string to files, so I can't see what would be different.

Any help aprreciated,

Thanks
 
I have come up with some code that will read the current value the relevant textfile and adds 1. Now I need it to write to the relevant textfile with the new value. This part is what is causing the error each time. So how do I write the value content to the file denoted by the varialbe name

My code so far:

<html><head>
<TITLE>formradiorespond.asp</TITLE>
</head><body bgcolor=&quot;#FFFFFF&quot;>
<%


' Set up Constants
Const ForWriting = 8 ' Input OutPut mode
Const Create = True

Dim MyFile
Dim fs ' FileSystemObject
Dim caption,name,content

caption = request.form(&quot;caption&quot;)

response.write caption

Select Case caption
case 1
MyFile = Server.MapPath(&quot;vote1.txt&quot;)
name=&quot;vote1.txt&quot;
case 2
MyFile = Server.MapPath(&quot;vote2.txt&quot;)
name=&quot;vote2.txt&quot;
case 3
MyFile = Server.MapPath(&quot;vote3.txt&quot;)
name=&quot;vote3.txt&quot;
end select

' Use MapPath function to get the Physical Path of file
Set fs = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set f=fs.OpenTextFile(myfile, 1)

content = f.ReadAll

If content = &quot;&quot; Then
content = 0
End If

f.Close


content = content + 1

Set f=fs.CreateTextFile(vote1.txt,true)
f.write(content)
f.close



'empty the objects
Set f=Nothing
Set fs=Nothing

Response.Write(content)


%>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top