我自己开发的一个简单的投票程序
tp.asp文件
<%response.buffer=true%> <html> <head> <title>投票处理页</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head>
<body bgcolor="#CCFFCC"> <% ip=request("REMOTE_ADDR") name=request("name") if trim(name)="" then response.write "您没有选择要投票的人" else dim c(20) dim d(20) dim d2(20) Set fs=CreateObject("Scripting.FileSystemObject") Set a=fs.openTextFile(server.mappath("tp.txt")) tpcount=cint(a.readline) for i=0 to tpcount-1 c(i)=a.readline d(i)=a.readline next for i=0 to tpcount-1 if name=c(i) then d(i)=d(i)+1 end if next Set fs = CreateObject("Scripting.FileSystemObject") Set a=fs.createTextfile(server.mappath("tp.txt")) a.writeline(tpcount) for i=0 to tpcount-1 a.writeline(c(i)) a.writeline(d(i)) next end if %> <br><br><center><a href="tp.asp#" onclick="window.history.back()">返回</a></center> </body> </html>
tp.txt文件
--------
5 成龙 11 周润发 4 林青霞 1 林志颖 3 李连杰 3
tp1.asp文件
---------
<% dim c(20) dim d(20) dim d2(20) Set fs=CreateObject("Scripting.FileSystemObject") Set a=fs.openTextFile(server.mappath("tp.txt")) tpcount=cint(a.readline) for i=0 to tpcount-1 c(i)=a.readline d(i)=a.readline next all=0 for i=0 to tpcount-1 all=all+d(i) next for i=0 to tpcount-1 t=t+d(i) next if t>0 then for i=0 to tpcount-1 d2(i)=formatpercent((d(i)/all),2,-1) next disptp=100 else for i=0 to tpcount-1 d2(i)=formatpercent((0),2,-1) next disptp=0 end if
response.write "document.write("&chr(34)&"<table width=220 border=1 height=55 bordercolor=#0000FF cellspacing=0>"&chr(34)&");" response.write "document.write("&chr(34)&"<tr><td width=80 height=26>参赛人</td> <td width=80 height=26>票数</td><td width=60 height=26>投票率</td></tr>"&chr(34)&");" for i=0 to tpcount-1 response.write "document.write("&chr(34)&"<tr><td width=80 height=24>"&c(i)&"</td><td width=80 height=24>"&d(i)&"</td><td width=60 height=24>"&d2(i)&" </td></tr>"&chr(34)&");" next response.write "document.write("&chr(34)&"<tr><td width=80 height=26> </td> <td width=80 height=26>"&all&"</td><td width=60 height=26>"&disptp&"% </td></tr></table>"&chr(34)&");" response.write "document.write("&chr(34)&"<form method=post action=../cgi/tp/tp.asp>我认为<select name=name>"&chr(34)&");" for i=0 to tpcount-1 response.write "document.write("&chr(34)&"<option value="&c(i)&">"&c(i)&"</option>"&chr(34)&");" next response.write "document.write("&chr(34)&"</select>的故事写得比较好。<br><input type=submit name=send value=投票></form>"&chr(34)&");" %> 
|