Request.Form and radio buttons
am 24.09.2006 18:05:22 von codeitHi,
On a page with server-code generated radio buttons (quiz format from 1
to 5 answers max), there is a Submit button. After this button is
clicked, a page shows the answers and other stats. The problem is that
I keep on getting the same error frequently only if more than a certain
number of questions are answered, depending on which questions are
answered. If less than, say, half a dozen questions are answered, there
is no error. Am I posting a string too long and beyond some limit? I
doubt it.
The line giving the error is: Do While rst("iQuestID") <> CInt(x)
This line is in the Sub Quizscore(), in the For Each loop.
Any ideas?
Error example:
============================================
Error Type:
(0x80020009)
Exception occurred.
/AllQuizzes/xlGenGeneral.asp, line 76
Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322)
Page:
POST 60 bytes to /AllQuizzes/xlGenGeneral.asp
POST Data:
1=2&2=3&3=4&4=3&5=3&6=3&7=4&8=3&9=3&10=2&11=3&12=3&13=4&14=2
=============================================
<%
Dim conntemp
Dim rst
set oCon=Server.CreateObject("ADODB.Connection")
ocon.Provider="Microsoft.Jet.OLEDB.4.0"
oCon.Open server.mappath("/_private/General.mdb")
Set rst=Server.CreateObject("ADODB.Recordset")
rst.Open "SELECT iQuestID, mQuest, mAns1, mAns2, mAns3, mAns4,
mAns5, iCorrectAns FROM tblGeneral", oCon
If Request.Form.Count = 0 Then
Call Quizpresent
Else
Call Quizscore
End If
oCon.close
set oCon = nothing
%>
<% Sub Quizpresent() %>
<% session("referer") = Request.ServerVariables("HTTP_REFERER") %>
<% End Sub %>
<%
Sub Quizscore()
Dim x
Dim iTotal
Dim iAnswered
Dim iNotAnswered
Dim iCorrect
Dim iCorrectCount
Dim iChosen
iTotal = 0
icorrectCount = 0
%>
Quiz results:
<%
For Each x in Request.Form
Do While rst("iQuestID") <> CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst("iCorrectAns"))
iChosen = CInt(Request.Form(x))
%>
The question<%=rst("iQuestID")%>was:<%=rst("mQuest") %>
Your answer was:<%= rst.fields(iChosen+1).value %>.
<%
If iChosen = iCorrect Then
iCorrectCount = iCorrectCount + 1
%>
Correct answer.
<%
Else
%>
Incorrect answer. The correct answer
is:<%=rst.fields(iCorrect+1)%>.
<%
End If
Next
rst.MoveFirst
While Not rst.EOF
iTotal = iTotal + 1
rst.MoveNext
Wend
%>
Quiz statistics:
Number of questions: <%=iTotal%>
<%iAnswered=Request.Form.Count%>
Number of questions
answered: <%=iAnswered%> or <%=FormatPercent(iAnswered/iTotal,0)%>
<%iNotAnswered=iTotal-iAnswered%>
Number of questions not
answered: <%=iNotAnswered%> or <%=FormatPercent(iNotAnswered/iTotal,0)%>
You answered correctly <%=iCorrectCount%> out of <%=iTotal%>
questions
and your score is : <%=FormatPercent(iCorrectCount /
iTotal,0)%>
<% End Sub %>