一个简单的投票程序

 

我自己开发的一个简单的投票程序

tp.asp文件

<%response.buffer=true%>


投票处理页


<%
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
%>


返回



 

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)&"

"&chr(34)&");"
response.write "document.write("&chr(34)&"    "&chr(34)&");"
for i=0 to tpcount-1
response.write "document.write("&chr(34)&""&chr(34)&");"
next
response.write "document.write("&chr(34)&"   
参赛人票数投票率
"&c(i)&""&d(i)&""&d2(i)&" 
 "&all&""&disptp&"% 
"&chr(34)&");"
response.write "document.write("&chr(34)&"
我认为的故事写得比较好。
"&chr(34)&");"
%>

你可能感兴趣的:(ASP)