Source Code of result.asp file:
<!--
Beginning of the ASP -->
<HTML>
<HEAD>
<TITLE>KV's Kool ASP - Opinion Poll Sample</TITLE>
<%
' Declare Variables
' Please note that there is only one data type (and it is called
"variant") in ASP; So, there is no need of specifying the data type
Dim fileSysObj, tf, pollFile
Dim question, option1, option2, option3
Dim val1, val2, val3
Dim pollTotal, poll1, poll2, poll3
' Read the Poll Information
pollFile = "pollInfo.txt"
pollFile = LEFT(Server.Mappath(Request.ServerVariables("PATH_INFO")),
InStrRev(Server.Mappath(Request.ServerVariables("PATH_INFO")), "\")) & pollFile
Set fileSysObj = createObject("Scripting.FileSystemObject")
IF (fileSysObj.FileExists(pollFile)) Then
' open the file for reading
if file exists
Set tf = filesysobj.OpenTextFile(pollFile, 1)
question = tf.ReadLine
option1 = tf.ReadLine
option2 = tf.ReadLine
option3 = tf.ReadLine
tf.Close
ELSE
' take default values if file does not exist
question = "This is a Sample Poll - and you are requested to participate."
option1 = "This Sample is Good"
option2 = "No, this is not Good"
option3 = "I can't Say"
END IF
' Read Poll Results from
poll data file and
' store number of votes polled for first option into val1
' number of votes polled for second option into val2
' number of votes polled for third option into val3
pollFile = "polldata.txt"
pollFile = LEFT(Server.Mappath(Request.ServerVariables("PATH_INFO")),
InStrRev(Server.Mappath(Request.ServerVariables("PATH_INFO")), "\")) & pollFile
IF (fileSysObj.FileExists(pollFile)) Then
' open the file for reading
if file exists
Set tf =
filesysobj.OpenTextFile(pollFile, 1)
val1 = tf.ReadLine
val2 = tf.ReadLine
val3 = tf.ReadLine
tf.Close
ELSE
'
initialize values to zero if file does not exist
val1 = 0
val2 = 0
val3 = 0
END IF
' Increment corresponding
variable's value by one
SELECT CASE Request.form("rboptions")
CASE 1
val1 = val1 + 1
CASE 2
val2 = val2 + 1
CASE 3
val3 = val3 + 1
END SELECT
' store the values back to
the file
'
create the file afresh, overwriting the existing file
Set tf =
fileSysObj.CreateTextFile(pollFile, True)
tf.WriteLine(val1)
tf.WriteLine(val2)
tf.WriteLine(val3)
tf.Close
' Calculate Percentages
' Store total number of votes
polled into a variable called pollTotal
pollTotal = CINT(val1) + CINT(val2) + CINT(val3)
' Don't Calculate Percentage if
total polled votes are zero, to avoid division by zero
' Store percentage of votes
polled for first option into poll1, second option into poll2 and third option
into poll3
IF pollTotal = 0 THEN
poll1 = 0
poll2 = 0
poll3 = 0
ELSE
' restrict
the decimal places in percentages to two
poll1 = INT(((val1 * 100) /
pollTotal) * 100) / 100
poll2 = INT(((val2 * 100) / pollTotal) * 100) / 100
poll3 = INT(((val3 * 100) / pollTotal) * 100) / 100
END IF
%>
</HEAD>
<BODY>
<div align="center"><center>
<table border="0" cellpadding="0" cellspacing="0" width="598">
<tr>
<td><p align="center"><font face="Arial" size="3"><strong><br>
<%
' Display the Poll Question
Response.Write(question)
%>
</strong></font></td>
</tr>
<tr>
<td><font color="#FFFFFF" face="Arial" size="3"><strong>.</strong></font></td>
</tr>
</table>
</center></div><div align="center"><center>
<table border="1" cellPadding="5" cellSpacing="5" width="350"
bordercolor="#C0C0C0">
<tr>
<td bgcolor="#E1E1E1"><p align="center"><strong>Response</strong> </td>
<td bgcolor="#E1E1E1"><p align="center"><strong>Percentage</strong> </td>
<td bgcolor="#E1E1E1"><p align="center"><strong>Votes Polled</strong> </td>
</tr>
<tr>
<td><strong>
<!-- Show the First Option
-->
<%=option1%>
</strong></td>
<td align="center">
<!-- Show the Number of
votes polled for First Option -->
<%=poll1%>
</td>
<td align="center">
<!-- Show the percentage
votes polled for First Option -->
<%=val1%>
</td>
</tr>
<tr>
<td><strong>
<%=option2%>
</strong></td>
<td align="center">
<%=poll2%>
</td>
<td align="center">
<%=val2%>
</td>
</tr>
<tr>
<td><strong>
<%=option3%>
</strong></td>
<td align="center">
<%=poll3%>
</td>
<td align="center">
<%=val3%>
</td>
</tr>
<tr>
<td><font color="#ffffff">.</font></td>
<td align="right"><strong>Total</strong></td>
<td align="center">
<!-- Show the total votes
polled -->
<%=pollTotal%>
</td>
</tr>
</table>
</center></div>
</BODY>
</HTML>
<!-- End of the ASP -->
back to Overview
|