|
<% On Error GoTo 0
Const Filename = "s1-0.txt"
Const ForReading = 1, ForWriting = 2, ForAppending = 8
dim sRace, iNumCandidate, iWinningCandidate, iHighestNumber, iTotalVotes, filesys, filetxt, readfile, filepath, iQuote1, iQuote2, iSpace1, iSpace2, x
Dim CandidateArray()
'store the race name, precincts in and counter, total # of precincts voting
'store the candidate name, party (if any), number of votes
'store total votes for race
filepath = Server.MapPath(Filename)
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(filepath) Then%>
<% Set readfile = filesys.OpenTextFile(filepath, ForReading, False) 'dont create the file if it is not there
readfile.readline 'get past first two lines of the file
readfile.readline
Do Until readfile.AtEndOfStream
filetxt = readfile.readline%>
| |
<%iQuote1 = InStr(filetxt,"""") 'first quote of race name
iQuote1 = CInt(iQuote1+1) 'move past the first quote
iQuote2 = CInt(InStr(iQuote1,filetxt,"""")) 'ending quote of race name
sRace = Mid(filetxt,iQuote1, (iQuote2-iQuote1)) 'the race name
iNumCandidate = CInt(Mid(filetxt,(iQuote2+2),(InStr((iQuote2+2),filetxt," "))-(iQuote2+2))) 'get the number of candidates after the race title
ReDim CandidateArray((iNumCandidate-1), 1)
iSpace1 = InStrRev(filetxt," ") 'position of last space on line
iSpace2 = InStrRev(filetxt," ",(iSpace1-1)) 'position of second to last space on line
Response.write("" & sRace & "") 'write out the race title%>
|
| |
.
|
Votes
|
% of votes counted
|
<%'Now work on writing out the candidates and their information
iHighestNumber = 0
iTotalVotes = 0
For x = 0 to (iNumCandidate-1)
filetxt = readfile.readline ' get next candidate
iQuote1 = InStr(filetxt,"""") 'first quote of Candidate name
iQuote1 = CInt(iQuote1+1) 'move past the first quote
iQuote2 = CInt(InStr(iQuote1,filetxt,"""")) 'ending quote of candidate name
while Mid(filetxt,iquote2-1,1) = "\"
iQuote2 = CInt(InStr(iQuote2+ 1,filetxt,""""))
wend
CandidateArray(x,0) = replace(Mid(filetxt,iQuote1, (iQuote2-iQuote1)),"\""","""") 'the candidate name
iQuote1 = InStr((iQuote2+1),filetxt,"""") 'first quote of Candidate party
iQuote2 = CInt(InStr((iQuote1+1),filetxt,"""")) 'ending quote of candidate party
If (iQuote2 <> (iQuote1+1)) Then 'party name found
CandidateArray(x,0) = CandidateArray(x,0) & " (" & Mid(filetxt,(iQuote1+1),(iQuote2-(iQuote1+1))) & ")"
End If
iSpace1 = InStrRev(filetxt," ") 'position of last space on line
CandidateArray(x,1) = CDbl(Mid(filetxt,(iSpace1+1))) ' Number of votes for Candidate
If (CandidateArray(x,1) > iHighestNumber) Then
iHighestNumber = CandidateArray(x,1) 'what is the hightest number of votes
End If
iTotalVotes = iTotalVotes + CandidateArray(x,1) 'number of total votes in this race
Next
For x = 0 to (iNumCandidate-1)
If (CandidateArray(x,1) = iHighestNumber) Then
Response.write("![]() | ")
Response.write("" & CandidateArray(x,0) & " | " & CandidateArray(x,1) & " | ")
If (iTotalVotes = 0) Then
Response.write("0")
Else
Response.write(Round(((CandidateArray(x,1)/iTotalVotes)*100),2))
End If
Response.write(" | ")
Else
Response.write(" ![]() | ")
Response.write("" & CandidateArray(x,0) & " | " & CandidateArray(x,1) & " | ")
If (iTotalVotes = 0) Then
Response.write("0")
Else
Response.write(Round(((CandidateArray(x,1)/iTotalVotes)*100),2))
End If
Response.write(" | ")
End If
Response.write(" ")
Next%>
| |
Totals: | <%=iTotalVotes%> |
|
<%Loop
readfile.close
Set readfile = nothing
Else%>
<% End If
SET filesys = nothing%>
<% If Err.Number <> 0 Then %>
<% =Err.Number%>
<% =Err.Clear%>
<% End If %>
|