M
marc_r_bertrand
To all asp/db pros:
The quiz code below works. But there is a problem when too many
questions are answered (radio buttons clicked). I am not an asp pro.
So, is there a pro out there or an amateur guru who will be so kind as
to volunteer some time to figure out where the bug is? This may mean he
will have to go through the tedious steps of creating an .mdb with a
few records...unless the bug is obvious...
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, starting from the bottom up or from the top down etc... If
less than, say, half a dozen questions are answered, there is no error.
Go figure...
The line giving the error is: Do While rst("iQuestID") <> CInt(x)
This line is in the Sub Quizscore(), in the For Each loop.
Error:
============================================
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") %>
<FORM METHOD="POST" ACTION="xlGenGeneral.asp">
<OL>
<%Do While Not rst.EOF%>
<%=rst("iQuestID")%> <%=rst("mQuest")%><BR>
<%
Dim i
Dim strChoice
For i = 1 to 5
strChoice = rst.fields(i+1).value
If strChoice <> "" Then
%>
<INPUT TYPE="RADIO" NAME="<%=rst("iQuestID")%>" VALUE="<%=i%>">
<%=strChoice%>
<BR>
<%
End If
Next
%>
<BR>
<%
rst.MoveNext
Loop
rst.MoveFirst
%>
<br>
<br>
</OL>
<P><INPUT TYPE="SUBMIT" VALUE="Get Score">
<INPUT TYPE="RESET" VALUE="Clear All Answers">
</FORM>
<% End Sub %>
<%
Sub Quizscore()
Dim x
Dim iTotal
Dim iAnswered
Dim iNotAnswered
Dim iCorrect
Dim iCorrectCount
Dim iChosen
iTotal = 0
icorrectCount = 0
%>
<HTML>
<BODY BGCOLOR="#ffffff">
<font size="2" face="Arial">
<h4>Quiz results:</h4>
<%
For Each x in Request.Form
Do While rst("iQuestID") <> CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst("iCorrectAns"))
iChosen = CInt(Request.Form(x))
%>
<P>
The question<%=rst("iQuestID")%>was:<%=rst("mQuest") %><BR>
Your answer was:<%= rst.fields(iChosen+1).value %>.<BR>
<%
If iChosen = iCorrect Then
iCorrectCount = iCorrectCount + 1
%>
<font color="#008000">Correct answer</font>.<BR>
<%
Else
%>
<font color="#FF00000">Incorrect answer</font>. The correct answer
is:<%=rst.fields(iCorrect+1)%>.<BR>
<%
End If
Next
rst.MoveFirst
While Not rst.EOF
iTotal = iTotal + 1
rst.MoveNext
Wend
%>
<br>
<br>
<hr>
<br>
<h4>Quiz statistics:</h4>
<br>
Number of questions: <%=iTotal%>
<br>
<%iAnswered=Request.Form.Count%>
<br>
Number of questions
answered: <%=iAnswered%> or <%=FormatPercent(iAnswered/iTotal,0)%>
<br>
<%iNotAnswered=iTotal-iAnswered%>
Number of questions not
answered: <%=iNotAnswered%> or <%=FormatPercent(iNotAnswered/iTotal,0)%>
<br>
<P><b>You answered correctly <%=iCorrectCount%> out of <%=iTotal%>
questions
and your score is : </b> <B><%=FormatPercent(iCorrectCount /
iTotal,0)%>
<br>
</font>
</BODY>
</HTML>
<% End Sub %>
==============================================================
The quiz code below works. But there is a problem when too many
questions are answered (radio buttons clicked). I am not an asp pro.
So, is there a pro out there or an amateur guru who will be so kind as
to volunteer some time to figure out where the bug is? This may mean he
will have to go through the tedious steps of creating an .mdb with a
few records...unless the bug is obvious...
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, starting from the bottom up or from the top down etc... If
less than, say, half a dozen questions are answered, there is no error.
Go figure...
The line giving the error is: Do While rst("iQuestID") <> CInt(x)
This line is in the Sub Quizscore(), in the For Each loop.
Error:
============================================
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") %>
<FORM METHOD="POST" ACTION="xlGenGeneral.asp">
<OL>
<%Do While Not rst.EOF%>
<%=rst("iQuestID")%> <%=rst("mQuest")%><BR>
<%
Dim i
Dim strChoice
For i = 1 to 5
strChoice = rst.fields(i+1).value
If strChoice <> "" Then
%>
<INPUT TYPE="RADIO" NAME="<%=rst("iQuestID")%>" VALUE="<%=i%>">
<%=strChoice%>
<BR>
<%
End If
Next
%>
<BR>
<%
rst.MoveNext
Loop
rst.MoveFirst
%>
<br>
<br>
</OL>
<P><INPUT TYPE="SUBMIT" VALUE="Get Score">
<INPUT TYPE="RESET" VALUE="Clear All Answers">
</FORM>
<% End Sub %>
<%
Sub Quizscore()
Dim x
Dim iTotal
Dim iAnswered
Dim iNotAnswered
Dim iCorrect
Dim iCorrectCount
Dim iChosen
iTotal = 0
icorrectCount = 0
%>
<HTML>
<BODY BGCOLOR="#ffffff">
<font size="2" face="Arial">
<h4>Quiz results:</h4>
<%
For Each x in Request.Form
Do While rst("iQuestID") <> CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst("iCorrectAns"))
iChosen = CInt(Request.Form(x))
%>
<P>
The question<%=rst("iQuestID")%>was:<%=rst("mQuest") %><BR>
Your answer was:<%= rst.fields(iChosen+1).value %>.<BR>
<%
If iChosen = iCorrect Then
iCorrectCount = iCorrectCount + 1
%>
<font color="#008000">Correct answer</font>.<BR>
<%
Else
%>
<font color="#FF00000">Incorrect answer</font>. The correct answer
is:<%=rst.fields(iCorrect+1)%>.<BR>
<%
End If
Next
rst.MoveFirst
While Not rst.EOF
iTotal = iTotal + 1
rst.MoveNext
Wend
%>
<br>
<br>
<hr>
<br>
<h4>Quiz statistics:</h4>
<br>
Number of questions: <%=iTotal%>
<br>
<%iAnswered=Request.Form.Count%>
<br>
Number of questions
answered: <%=iAnswered%> or <%=FormatPercent(iAnswered/iTotal,0)%>
<br>
<%iNotAnswered=iTotal-iAnswered%>
Number of questions not
answered: <%=iNotAnswered%> or <%=FormatPercent(iNotAnswered/iTotal,0)%>
<br>
<P><b>You answered correctly <%=iCorrectCount%> out of <%=iTotal%>
questions
and your score is : </b> <B><%=FormatPercent(iCorrectCount /
iTotal,0)%>
<br>
</font>
</BODY>
</HTML>
<% End Sub %>
==============================================================