本人仿照一本书上的程序写下的,但不知是原程序本身有问题,还是自己在哪个细节出了错:点击所选城市图片后,投票数未能加一,就出现了“您已经投过票,不能重复投票!”程序如下,敬请指点,先谢谢了!
*****************************************************************************************
<%
'定义用于从给定文件(只)读取票数的函数:
Function ReadCount(CFile)
Dim objFSO,objTS
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
Set objTS=objFSO.OpenTextFile(Server.MapPath(CFile),1,True) '1,为只读
If Not objTS.AtEndOfStream Then
ReadCount=CLng(objTS.ReadLine)
Else
ReadCount=0
End If
objTS.Close
Set objFSO= Nothing
End Function
'定义用于将累计票数(只)写入指定文件的sub过程:
Sub WriteCount(CFile,Count)
Dim objFSO,objTS
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
Set objTS=objFSO.OpenTextFile(Server.MapPath(CFile),2,True) '2,为只写
objTS.WriteLine(Count)
objTS.Close
Set objFSO= Nothing
End Sub
%>
<%
Dim Vote,London1,Paris1,Sanfran1,Repeat
Application.Lock()
'获取浏览者所投票的城市:
Vote=Request("Vote")
'从相应文件分别读取各城市已获得的票数
London1=ReadCount("London.txt")
Paris1=ReadCount("Paris.txt")
Sanfran1=ReadCount("Sanfran.txt")
'限制重复投票
If (vote<>Empty)And(Session("Repeat")=True) Then
Response.Write("您已经投过票,不能重复投票!")
Response.End
Else
' 判断当前得票的城市,并为其票数加1后写入对应文件:
If Vote="London" Then
London1=London1+1
WriteCount"London.txt",London1
ElseIf Vote="Paris" Then
Paris1=Paris1+1
WriteCount"Paris.txt",Paris1
ElseIf Vote="Sanfran" Then
Sanfran1=Sanfran1+1
WriteCount"Sanfran.txt",Sanfran1
End If
Session("Repeat")=True
End If
Application.UnLock()
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>魅力城市网上投票</title>
<style type="text/css">
<!--
.chengshi {
font-family: "黑体";
font-size: 20px;
color: #00CCFF;
}
.wenzi {
font-size: 75%;
color: #00CCFF;
}
.touming {
filter: Alpha(Opacity=200, Style=3);
}
body {
margin-top: 100px;
}
-->
</style>
</head>
<body bgcolor="#000000"><center>
<p class="chengshi">魅力城市网上投票</p>
<p> </p>
<table width="400" bgcolor="#OOOOOO">
<tr>
<td align="center"><a href="poll.asp?Vote=London"><img src="../../img/London.jpg" width="102" height="104" border="1" class="touming"></td>
<td align="center"><a href="poll.asp?Vote=Paris"><img src="../../img/Paris.jpg" width="101" height="104" border="1" class="touming"></td>
<td align="center"><a href="poll.asp?Vote=Sanfran"><img src="../../img/Sanfran.jpg" width="104" height="93" border="1" class="touming"></td>
</tr>
<tr>
<td align="center"><span class="wenzi">伦敦得票数:</span><font color="#FFFFFF"><%=London1%></font></td>
<td align="center"><span class="wenzi">巴黎得票数:</span><font color="#FFFFFF"><%=Paris1%></font></td>
<td align="center"><span class="wenzi">旧金山得票数:</span><font color="#FFFFFF"><%=Sanfran1%></font></td>
</tr>
</table><p>
<span class="wenzi">请用鼠标点击一下您所喜欢的城市图片</span><p>
<span class="wenzi">该市就可以获得您宝贵的一票!</span>
</center></body>
</html>
[此贴子已经被作者于2007-2-3 18:51:17编辑过]