Voting examples
Function: Vote on the software and computer studio columns, choose your favorite columns.
Implementation method: The results of the vote exist in the Result.txt file, the current working page is voting.asp, the object submitted is voted.asp, when you click the View button, you can view the results of the current ballot. The bug in the middle is that when you submit, you continue to refresh the voted.asp, so that the ballot results are automatically added, think about why? What is the way to solve it? You've met a similar website.
The key to Voting.asp is:
1: Show viewing results
<script language=javascript>
function Windowopen (Loadpos)
{window.open (Loadpos, "Surveywin", "toolbar,resizable,scrollbars,dependent,width=400,height=480");
}
</SCRIPT>
2: Submit data to voted.asp <form method= "POST" action= "voted.asp" >
3:voted.asp's key is to the following two sentences, the first line is to save the number of software column votes, the second line is to save the number of votes in the computer Studio column. The next procedure is to automatically update the number of votes in the software column or the number of votes in the computer studio column based on the data submitted.
<%
Set files= Server.CreateObject ("Scripting.FileSystemObject")
If Request.Form ("R1") = "Soft" Then
Set filer= Files.opentextfile (Server.MapPath ("Result.txt"), 1, True)
Soft = Filer.readline
Studio = Filer.readline
Filer.close
Soft=int (Soft) +1
Set filer= Files.opentextfile (Server.MapPath ("Result.txt"), 2, True)
Filer.writeline Soft
Filer.writeline Studio
Filer.close
Else
Set filer= Files.opentextfile (Server.MapPath ("Result.txt"), 1, True)
Soft = Filer.readline
Studio = Filer.readline
Filer.close
Studio=int (Studio) +1
Set filer= Files.opentextfile (Server.MapPath ("Result.txt"), 2, True)
Filer.writeline Soft
Filer.writeline Studio
Filer.close
End If
%>
4: The following procedure gets the number of votes in two columns, calculating the percentages and the number of votes.
<%
Set files= Server.CreateObject ("Scripting.FileSystemObject")
Set filer= Files.opentextfile (Server.MapPath ("Result.txt"), 1, True)
Osoft=filer.readline
Ostudio=filer.readline
Filer.close
ncount = Int (osoft) +int (Ostudio)
soft= (M int (osoft))/int (ncount)
studio= (M int (ostudio))/int (ncount)
Soft = FormatNumber (Soft, 2)
Studio = FormatNumber (Studio, 2)
%>