Home All Groups Group Topic Archive Search About

Quizz script performance bug -- too many questions?

Author
8 Oct 2006 11:12 AM
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")%>&nbsp;&nbsp;<%=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:&nbsp;&nbsp;&nbsp;<%=iTotal%>
<br>
<%iAnswered=Request.Form.Count%>
<br>
Number of questions
answered:&nbsp;&nbsp;&nbsp;<%=iAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Forma­tPercent(iAnswered/iTotal,0)%>

<br>
<%iNotAnswered=iTotal-iAnswered%>
Number of questions not
answered:&nbsp;&nbsp;&nbsp;<%=iNotAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Fo­rmatPercent(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 %>
==============================================================

Author
8 Oct 2006 7:15 PM
Mike Brind
<marc_r_bertr***@hotmail.com> wrote in message
news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
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")%>&nbsp;&nbsp;<%=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:&nbsp;&nbsp;&nbsp;<%=iTotal%>
<br>
<%iAnswered=Request.Form.Count%>
<br>
Number of questions
answered:&nbsp;&nbsp;&nbsp;<%=iAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Forma­tPercent(iAnswered/iTotal,0)%>

<br>
<%iNotAnswered=iTotal-iAnswered%>
Number of questions not
answered:&nbsp;&nbsp;&nbsp;<%=iNotAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Fo­rmatPercent(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 %>
==============================================================

A least one x is not a number.  Request.Form("Submit") will always equal
"Get Score".  Add a condition within the For.. Each loop to omit this from
being converted to int.

For Each x in Request.Form
    If x <> "Submit" Then
      Do While rst("iQuestID") <> CInt(x)
        rst.MoveNext
      Loop
      iCorrect = CInt(rst("iCorrectAns"))
      iChosen = CInt(Request.Form(x))
....
....
    End If
Next

--
Mike Brind
Are all your drivers up to date? click for free checkup

Author
9 Oct 2006 11:04 AM
marc_r_bertrand
Mike Brind wrote:
Show quoteHide quote
> <marc_r_bertr***@hotmail.com> wrote in message
> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
> 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")%>&nbsp;&nbsp;<%=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:&nbsp;&nbsp;&nbsp;<%=iTotal%>
> <br>
> <%iAnswered=Request.Form.Count%>
> <br>
> Number of questions
> answered:&nbsp;&nbsp;&nbsp;<%=iAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Forma­tPercent(iAnswered/iTotal,0)%>
>
> <br>
> <%iNotAnswered=iTotal-iAnswered%>
> Number of questions not
> answered:&nbsp;&nbsp;&nbsp;<%=iNotAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Fo­rmatPercent(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 %>
> ==============================================================
>
> A least one x is not a number.  Request.Form("Submit") will always equal
> "Get Score".  Add a condition within the For.. Each loop to omit this from
> being converted to int.
>
> For Each x in Request.Form
>     If x <> "Submit" Then
>       Do While rst("iQuestID") <> CInt(x)
>         rst.MoveNext
>       Loop
>       iCorrect = CInt(rst("iCorrectAns"))
>       iChosen = CInt(Request.Form(x))
> ...
> ...
>     End If
> Next
>
> --
> Mike Brind
===============================================================================
Mike,

Thanks.

Nope. No luck. I still get the error:

Error Type:
(0x80020009)
Exception occurred.

I thought about your suggestion, and I wouldn't be surprised if I tried
it a long time ago. I tried lots of bits here and there before...I
can't remember what exactly. All I remember is that none worked.

I wasn't sure whether the bottom buttons mattered because the code
works as intended and no error is generated when a few questions are
answered. How come? Shouldn't it break at the end when the buttons get
in the loop? Also, I am not sure about which x's are processed first.
All radio buttons and then the last two buttons? I assumed so. Besides,
none of the buttons have a NAME argument, so I thought they were
skipped in the loop...

Anyway, even after insterting the If x <> "SUBMIT" Then or If x <>
"SUBMIT" AND x <> "RESET" Then, I still get the error.
I tried giving both buttons a NAME argument with a name, and that
didn't make a difference either.
Author
9 Oct 2006 11:50 AM
Mike Brind
<marc_r_bertr***@hotmail.com> wrote in message
news:1160391861.977900.208180@k70g2000cwa.googlegroups.com...

Mike Brind wrote:
Show quoteHide quote
> <marc_r_bertr***@hotmail.com> wrote in message
> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
> 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")%>&nbsp;&nbsp;<%=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:&nbsp;&nbsp;&nbsp;<%=iTotal%>
> <br>
> <%iAnswered=Request.Form.Count%>
> <br>
> Number of questions
> answered:&nbsp;&nbsp;&nbsp;<%=iAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Forma­tPercent(iAnswered/iTotal,0)%>
>
> <br>
> <%iNotAnswered=iTotal-iAnswered%>
> Number of questions not
> answered:&nbsp;&nbsp;&nbsp;<%=iNotAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Fo­rmatPercent(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 %>
> ==============================================================
>
> A least one x is not a number.  Request.Form("Submit") will always equal
> "Get Score".  Add a condition within the For.. Each loop to omit this from
> being converted to int.
>
> For Each x in Request.Form
>     If x <> "Submit" Then
>       Do While rst("iQuestID") <> CInt(x)
>         rst.MoveNext
>       Loop
>       iCorrect = CInt(rst("iCorrectAns"))
>       iChosen = CInt(Request.Form(x))
> ...
> ...
>     End If
> Next
>
> --
> Mike Brind
===============================================================================
>Mike,
>
>Thanks.
>
>Nope. No luck. I still get the error:
>
>Error Type:
>(
>0x80020009)
>Exception occurred.
>
>I thought about your suggestion, and I wouldn't be surprised if I tried
>it a long time ago. I tried lots of bits here and there before...I
>can't remember what exactly. All I remember is that none worked.
>
>I wasn't sure whether the bottom buttons mattered because the code
>works as intended and no error is generated when a few questions are
>answered. How come? Shouldn't it break at the end when the buttons get
>in the loop? Also, I am not sure about which x's are processed first.
>All radio buttons and then the last two buttons? I assumed so. Besides,
>none of the buttons have a NAME argument, so I thought they were
>skipped in the loop...

>Anyway, even after insterting the If x <> "SUBMIT" Then or If x <>
>"SUBMIT" AND x <> "RESET" Then, I still get the error.
>I tried giving both buttons a NAME argument with a name, and that
>didn't make a difference either.

In that case, rst is probably .EOF.  In other words, you have more values
being passed in the form collection than you have iQuestIDs in your
database.  So at some stage, you get to the end of the rst("iQuestID")
before you have finished comparing it to all values of Request.Form(x).

To check all values of the Form collection that are being passed, do this as
the first line in QuizPresent:

<%
For Each x in Request.Form
    Response.Write x & ": " & Request.Form(x) & "<br />"
Next
Response.End
%>

--
Mike Brind
Author
9 Oct 2006 11:54 AM
Mike Brind
Show quote Hide quote
"Mike Brind" <paxton***@hotmail.com> wrote in message
news:%23Dksfk56GHA.3732@TK2MSFTNGP05.phx.gbl...
> <marc_r_bertr***@hotmail.com> wrote in message
> news:1160391861.977900.208180@k70g2000cwa.googlegroups.com...
>
> Mike Brind wrote:
>> <marc_r_bertr***@hotmail.com> wrote in message
>> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
>> 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")%>&nbsp;&nbsp;<%=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:&nbsp;&nbsp;&nbsp;<%=iTotal%>
>> <br>
>> <%iAnswered=Request.Form.Count%>
>> <br>
>> Number of questions
>> answered:&nbsp;&nbsp;&nbsp;<%=iAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Forma­tPercent(iAnswered/iTotal,0)%>
>>
>> <br>
>> <%iNotAnswered=iTotal-iAnswered%>
>> Number of questions not
>> answered:&nbsp;&nbsp;&nbsp;<%=iNotAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Fo­rmatPercent(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 %>
>> ==============================================================
>>
>> A least one x is not a number.  Request.Form("Submit") will always equal
>> "Get Score".  Add a condition within the For.. Each loop to omit this
>> from
>> being converted to int.
>>
>> For Each x in Request.Form
>>     If x <> "Submit" Then
>>       Do While rst("iQuestID") <> CInt(x)
>>         rst.MoveNext
>>       Loop
>>       iCorrect = CInt(rst("iCorrectAns"))
>>       iChosen = CInt(Request.Form(x))
>> ...
>> ...
>>     End If
>> Next
>>
>> --
>> Mike Brind
> ===============================================================================
>>Mike,
>>
>>Thanks.
>>
>>Nope. No luck. I still get the error:
>>
>>Error Type:
>>(
>>0x80020009)
>>Exception occurred.
>>
>>I thought about your suggestion, and I wouldn't be surprised if I tried
>>it a long time ago. I tried lots of bits here and there before...I
>>can't remember what exactly. All I remember is that none worked.
>>
>>I wasn't sure whether the bottom buttons mattered because the code
>>works as intended and no error is generated when a few questions are
>>answered. How come? Shouldn't it break at the end when the buttons get
>>in the loop? Also, I am not sure about which x's are processed first.
>>All radio buttons and then the last two buttons? I assumed so. Besides,
>>none of the buttons have a NAME argument, so I thought they were
>>skipped in the loop...
>
>>Anyway, even after insterting the If x <> "SUBMIT" Then or If x <>
>>"SUBMIT" AND x <> "RESET" Then, I still get the error.
>>I tried giving both buttons a NAME argument with a name, and that
>>didn't make a difference either.
>
> In that case, rst is probably .EOF.  In other words, you have more values
> being passed in the form collection than you have iQuestIDs in your
> database.  So at some stage, you get to the end of the rst("iQuestID")
> before you have finished comparing it to all values of Request.Form(x).
>
> To check all values of the Form collection that are being passed, do this
> as the first line in QuizPresent:
>

Oops - that should of course be QuizScore, not QuizPresent...
Author
9 Oct 2006 4:26 PM
marc_r_bertrand
Mike Brind wrote:
Show quoteHide quote
> "Mike Brind" <paxton***@hotmail.com> wrote in message
> news:%23Dksfk56GHA.3732@TK2MSFTNGP05.phx.gbl...
> > <marc_r_bertr***@hotmail.com> wrote in message
> > news:1160391861.977900.208180@k70g2000cwa.googlegroups.com...
> >
> > Mike Brind wrote:
> >> <marc_r_bertr***@hotmail.com> wrote in message
> >> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
> >> 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")%>&nbsp;&nbsp;<%=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:&nbsp;&nbsp;&nbsp;<%=iTotal%>
> >> <br>
> >> <%iAnswered=Request.Form.Count%>
> >> <br>
> >> Number of questions
> >> answered:&nbsp;&nbsp;&nbsp;<%=iAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Forma­tPercent(iAnswered/iTotal,0)%>
> >>
> >> <br>
> >> <%iNotAnswered=iTotal-iAnswered%>
> >> Number of questions not
> >> answered:&nbsp;&nbsp;&nbsp;<%=iNotAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Fo­rmatPercent(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 %>
> >> ==============================================================
> >>
> >> A least one x is not a number.  Request.Form("Submit") will always equal
> >> "Get Score".  Add a condition within the For.. Each loop to omit this
> >> from
> >> being converted to int.
> >>
> >> For Each x in Request.Form
> >>     If x <> "Submit" Then
> >>       Do While rst("iQuestID") <> CInt(x)
> >>         rst.MoveNext
> >>       Loop
> >>       iCorrect = CInt(rst("iCorrectAns"))
> >>       iChosen = CInt(Request.Form(x))
> >> ...
> >> ...
> >>     End If
> >> Next
> >>
> >> --
> >> Mike Brind
> > ===============================================================================
> >>Mike,
> >>
> >>Thanks.
> >>
> >>Nope. No luck. I still get the error:
> >>
> >>Error Type:
> >>(
> >>0x80020009)
> >>Exception occurred.
> >>
> >>I thought about your suggestion, and I wouldn't be surprised if I tried
> >>it a long time ago. I tried lots of bits here and there before...I
> >>can't remember what exactly. All I remember is that none worked.
> >>
> >>I wasn't sure whether the bottom buttons mattered because the code
> >>works as intended and no error is generated when a few questions are
> >>answered. How come? Shouldn't it break at the end when the buttons get
> >>in the loop? Also, I am not sure about which x's are processed first.
> >>All radio buttons and then the last two buttons? I assumed so. Besides,
> >>none of the buttons have a NAME argument, so I thought they were
> >>skipped in the loop...
> >
> >>Anyway, even after insterting the If x <> "SUBMIT" Then or If x <>
> >>"SUBMIT" AND x <> "RESET" Then, I still get the error.
> >>I tried giving both buttons a NAME argument with a name, and that
> >>didn't make a difference either.
> >
> > In that case, rst is probably .EOF.  In other words, you have more values
> > being passed in the form collection than you have iQuestIDs in your
> > database.  So at some stage, you get to the end of the rst("iQuestID")
> > before you have finished comparing it to all values of Request.Form(x).
> >
> > To check all values of the Form collection that are being passed, do this
> > as the first line in QuizPresent:
> >
>
> Oops - that should of course be QuizScore, not QuizPresent...


===================================================================================
OK. This is what it produces:

1: 1
17: 1
29: 1
30: 1
2: 1
15: 1
27: 1
3: 1
13: 1
25: 1
4: 1
11: 1
23: 1
5: 1
21: 1
33: 1
6: 1
18: 1
31: 1
7: 1
16: 1
28: 1
8: 1
14: 1
26: 1
9: 1
12: 1
24: 1
10: 1
22: 1
19: 1
20: 1
32: 1

There are 33 records in the db.
Answering each first option and clicking on the Get Score button still
gives an error
on the line: Do While rst("iQuestID") <> CInt(x):

Error Type:
(0x80020009)
Exception occurred.
/AllQuizzes/xlGenGeneral0.asp, line 84

Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322)

Page:
POST 155 bytes to /AllQuizzes/xlGenGeneral0.asp

POST Data:
1=1&2=1&3=1&4=1&5=1&6=1&7=1&8=1&9=1&10=1&11=1&12=1&13=1&14=1&15=1&16=1&17=1&18=1&19=1&20=1&21=1&22=1&23=1&24=1&25=1&26=1&27=1&28=1&29=1&30=1&31=1&32=1&33=1

====================================================================================
Author
9 Oct 2006 4:45 PM
marc_r_bertrand
Mike Brind wrote:
Show quoteHide quote
> "Mike Brind" <paxton***@hotmail.com> wrote in message
> news:%23Dksfk56GHA.3732@TK2MSFTNGP05.phx.gbl...
> > <marc_r_bertr***@hotmail.com> wrote in message
> > news:1160391861.977900.208180@k70g2000cwa.googlegroups.com...
> >
> > Mike Brind wrote:
> >> <marc_r_bertr***@hotmail.com> wrote in message
> >> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
> >> 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")%>&nbsp;&nbsp;<%=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:&nbsp;&nbsp;&nbsp;<%=iTotal%>
> >> <br>
> >> <%iAnswered=Request.Form.Count%>
> >> <br>
> >> Number of questions
> >> answered:&nbsp;&nbsp;&nbsp;<%=iAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Forma­tPercent(iAnswered/iTotal,0)%>
> >>
> >> <br>
> >> <%iNotAnswered=iTotal-iAnswered%>
> >> Number of questions not
> >> answered:&nbsp;&nbsp;&nbsp;<%=iNotAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=Fo­rmatPercent(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 %>
> >> ==============================================================
> >>
> >> A least one x is not a number.  Request.Form("Submit") will always equal
> >> "Get Score".  Add a condition within the For.. Each loop to omit this
> >> from
> >> being converted to int.
> >>
> >> For Each x in Request.Form
> >>     If x <> "Submit" Then
> >>       Do While rst("iQuestID") <> CInt(x)
> >>         rst.MoveNext
> >>       Loop
> >>       iCorrect = CInt(rst("iCorrectAns"))
> >>       iChosen = CInt(Request.Form(x))
> >> ...
> >> ...
> >>     End If
> >> Next
> >>
> >> --
> >> Mike Brind
> > ===============================================================================
> >>Mike,
> >>
> >>Thanks.
> >>
> >>Nope. No luck. I still get the error:
> >>
> >>Error Type:
> >>(
> >>0x80020009)
> >>Exception occurred.
> >>
> >>I thought about your suggestion, and I wouldn't be surprised if I tried
> >>it a long time ago. I tried lots of bits here and there before...I
> >>can't remember what exactly. All I remember is that none worked.
> >>
> >>I wasn't sure whether the bottom buttons mattered because the code
> >>works as intended and no error is generated when a few questions are
> >>answered. How come? Shouldn't it break at the end when the buttons get
> >>in the loop? Also, I am not sure about which x's are processed first.
> >>All radio buttons and then the last two buttons? I assumed so. Besides,
> >>none of the buttons have a NAME argument, so I thought they were
> >>skipped in the loop...
> >
> >>Anyway, even after insterting the If x <> "SUBMIT" Then or If x <>
> >>"SUBMIT" AND x <> "RESET" Then, I still get the error.
> >>I tried giving both buttons a NAME argument with a name, and that
> >>didn't make a difference either.
> >
> > In that case, rst is probably .EOF.  In other words, you have more values
> > being passed in the form collection than you have iQuestIDs in your
> > database.  So at some stage, you get to the end of the rst("iQuestID")
> > before you have finished comparing it to all values of Request.Form(x).
> >
> > To check all values of the Form collection that are being passed, do this
> > as the first line in QuizPresent:
> >
>
> Oops - that should of course be QuizScore, not QuizPresent...

====================================================================
Answering 10 questions produces an OK result; 11, and the code breaks.



Quiz results:


Question 1 was: blaQuestion1
Your answer was: blaAnswer1Q1.
Incorrect answer. The correct answer is: blaAnswer4Q1.


Question 2 was: blaQuestion2
Your answer was: blaAnswer1Q2.
Correct answer.


Question 3 was: blaQuestion3
Your answer was: blaAnswer1Q3.
Incorrect answer. The correct answer is: blaAnswer3Q3.


Question 4 was: blaQuestion4
Your answer was: blaAnswer1Q4.
Incorrect answer. The correct answer is: blaAnswer2Q4.


Question 5 was: blaQuestion5
Your answer was: blaAnswer1Q5.
Incorrect answer. The correct answer is: blaAnswer3Q5.


Question 6 was: blaQuestion6
Your answer was: blaAnswer1Q6.
Incorrect answer. The correct answer is: blaAnswer2Q6.


Question 7 was: blaQuestion7
Your answer was: blaAnswer1Q7.
Correct answer.


Question 8 was: blaQuestion8
Your answer was: blaAnswer1Q8.
Incorrect answer. The correct answer is: blaAnswer2Q8.


Question 9 was: blaQuestion9
Your answer was: blaAnswer1Q9.
Incorrect answer. The correct answer is: blaAnswer3Q9.


Question 10 was: blaQuestion10
Your answer was: blaAnswer1Q10.
Correct answer.





--------------------------------------------------------------------------------


Quiz statistics:

Number of questions:   33

Number of questions answered:   10  or  30%
Number of questions not answered:   23  or  70%

You answered correctly 3 out of 33 questions and your score is : 9%
Author
9 Oct 2006 7:57 PM
Mike Brind
<marc_r_bertr***@hotmail.com> wrote in message
news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
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
=============================================
<snip>

<%
    For Each x in Request.Form
      Do While rst("iQuestID") <> CInt(x)
        rst.MoveNext
      Loop
      iCorrect = CInt(rst("iCorrectAns"))
      iChosen = CInt(Request.Form(x))
%>


At this point, it went into an infinite loop when I put on error resume next
in.  The reason is that rst did try to go beyond EOF, because there is no
instruction for it to stop at EOF.

You could try Do While rst("iQuestID") <> CInt(x) And Not rst.EOF

The following should work, and makes use of GetRows, to save keeping the
recordset open for so long.  It also gets rid of the While... Wend loop to
calculate the total number of questions:

<%

   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 Not rst.EOF Then arr = rst.GetRows
rst.Close : Set rst = Nothing
oCon.close : set oCon = nothing

   If Request.Form.Count = 0 Then
      Call Quizpresent
   Else
      Call Quizscore
   End If

Sub Quizpresent() %>
<% session("referer") = Request.ServerVariables("HTTP_REFERER") %>
<FORM METHOD="POST" ACTION="quiz.asp">
<OL>
<%If Isarray(arr) Then
For a = 0 to Ubound(arr,2)
%>
<%= arr(0,a)%>&nbsp;&nbsp;<%=arr(1,a)%><BR>
<%
   Dim i
   Dim strChoice
   For i = 1 to 5
     strChoice = arr(i+1,a)
     If strChoice <> "" Then
%>
<INPUT TYPE="RADIO" NAME="<%=arr(0,a)%>" VALUE="<%=i%>">
<%=strChoice%>
<BR>
<%
     End If
   Next
%>
<BR>
<%
Next
%>
<br>
<br>
</OL>
<P><INPUT TYPE="SUBMIT" VALUE="Get Score">
<INPUT TYPE="RESET" VALUE="Clear All Answers">
</FORM>

<%End If
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
  j=0
       Do Until Cint(arr(0,j)) = CInt(x)
     j=j+1
       Loop

      iCorrect = CInt(arr(7,j))
      iChosen = CInt(Request.Form(x))
%>
<P>
The question <%=arr(0,j)%> was:<%=arr(1,j) %><BR>
Your answer was:<%= iChosen %>.<BR>
<%
      If iChosen = iCorrect Then
          iCorrectCount = iCorrectCount + 1
%>
<font color="#008000">Correct answer</font>.<BR>
<%
      Else
   CorrectAnswer = arr(7,j)
%>
<font color="#FF00000">Incorrect answer</font>. The correct answer
is:<%=arr(CorrectAnswer+1,j)%>.<BR>
<%
      End If
   Next
     iTotal = Ubound(arr,2) + 1
%>
<br><br><hr><br>
<h4>Quiz statistics:</h4>
<br>
Number of questions:&nbsp;&nbsp;&nbsp;<%=iTotal%>
<br>
<%iAnswered=Request.Form.Count%>
<br>
Number of questions
answered:&nbsp;&nbsp;&nbsp;<%=iAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=FormatPercent(iAnswered/iTotal,0)%>

<br>
<%iNotAnswered=iTotal-iAnswered%>
Number of questions not
answered:&nbsp;&nbsp;&nbsp;<%=iNotAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=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 %>


--
Mike Brind
Author
10 Oct 2006 7:42 AM
marc_r_bertrand
Mike Brind wrote:
Show quoteHide quote
> <marc_r_bertr***@hotmail.com> wrote in message
> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
> 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
> =============================================
> <snip>
>
> <%
>     For Each x in Request.Form
>       Do While rst("iQuestID") <> CInt(x)
>         rst.MoveNext
>       Loop
>       iCorrect = CInt(rst("iCorrectAns"))
>       iChosen = CInt(Request.Form(x))
> %>
>
>
> At this point, it went into an infinite loop when I put on error resume next
> in.  The reason is that rst did try to go beyond EOF, because there is no
> instruction for it to stop at EOF.
>
> You could try Do While rst("iQuestID") <> CInt(x) And Not rst.EOF
>
> The following should work, and makes use of GetRows, to save keeping the
> recordset open for so long.  It also gets rid of the While... Wend loop to
> calculate the total number of questions:
>
> <%
>
>    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 Not rst.EOF Then arr = rst.GetRows
>  rst.Close : Set rst = Nothing
>  oCon.close : set oCon = nothing
>
>    If Request.Form.Count = 0 Then
>       Call Quizpresent
>    Else
>       Call Quizscore
>    End If
>
> Sub Quizpresent() %>
> <% session("referer") = Request.ServerVariables("HTTP_REFERER") %>
> <FORM METHOD="POST" ACTION="quiz.asp">
> <OL>
> <%If Isarray(arr) Then
>  For a = 0 to Ubound(arr,2)
> %>
> <%= arr(0,a)%>&nbsp;&nbsp;<%=arr(1,a)%><BR>
> <%
>    Dim i
>    Dim strChoice
>    For i = 1 to 5
>      strChoice = arr(i+1,a)
>      If strChoice <> "" Then
> %>
> <INPUT TYPE="RADIO" NAME="<%=arr(0,a)%>" VALUE="<%=i%>">
> <%=strChoice%>
> <BR>
> <%
>      End If
>    Next
> %>
> <BR>
> <%
> Next
> %>
> <br>
> <br>
> </OL>
> <P><INPUT TYPE="SUBMIT" VALUE="Get Score">
> <INPUT TYPE="RESET" VALUE="Clear All Answers">
> </FORM>
>
> <%End If
> 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
>   j=0
>        Do Until Cint(arr(0,j)) = CInt(x)
>      j=j+1
>        Loop
>
>       iCorrect = CInt(arr(7,j))
>       iChosen = CInt(Request.Form(x))
> %>
> <P>
> The question <%=arr(0,j)%> was:<%=arr(1,j) %><BR>
> Your answer was:<%= iChosen %>.<BR>
> <%
>       If iChosen = iCorrect Then
>           iCorrectCount = iCorrectCount + 1
> %>
> <font color="#008000">Correct answer</font>.<BR>
> <%
>       Else
>    CorrectAnswer = arr(7,j)
> %>
> <font color="#FF00000">Incorrect answer</font>. The correct answer
> is:<%=arr(CorrectAnswer+1,j)%>.<BR>
> <%
>       End If
>    Next
>      iTotal = Ubound(arr,2) + 1
> %>
> <br><br><hr><br>
> <h4>Quiz statistics:</h4>
> <br>
> Number of questions:&nbsp;&nbsp;&nbsp;<%=iTotal%>
> <br>
> <%iAnswered=Request.Form.Count%>
> <br>
> Number of questions
> answered:&nbsp;&nbsp;&nbsp;<%=iAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=FormatPercent(iAnswered/iTotal,0)%>
>
> <br>
> <%iNotAnswered=iTotal-iAnswered%>
> Number of questions not
> answered:&nbsp;&nbsp;&nbsp;<%=iNotAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=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 %>
>
>
> --
> Mike Brind

===================================================================================
Great!
It works (after changing the Action attribute of the form tag that is
:)). Now there is some serious progress. GetRows does it.
Bloody recordset!
I changed a few things in the stats area, just for aesthetic reasons.
I like the idea of closing that recordset very quickly.
Just one more thing: the Quizscore routine lists the questions in
complete disorder.

<%
Sub Quizscore()
    Dim x
    Dim iTotal
    Dim iAnswered
    Dim iNotAnswered
    Dim iCorrect
    Dim iCorrectCount
    Dim iChosen
    Dim iCorrectAns
    iTotal = 0
    icorrectCount = 0
%>
<HTML>
<BODY BGCOLOR="#ffffff">
<font size="2" face="Arial">
<h4>Quiz results:</h4>
<%
       For Each x in Request.Form
          j=0
          Do Until Cint(arr(0,j)) = CInt(x)
            j=j+1
          Loop


          iCorrect = CInt(arr(7,j))
          iChosen = CInt(Request.Form(x))
%>
<P>
Question <%=arr(0,j)%> was:&nbsp;<%=arr(1,j) %><BR>
Your answer was no. <% =iChosen %>:&nbsp;<%= arr(iChosen+1,j) %>.<BR>
<%
          If iChosen = iCorrect Then
             iCorrectCount = iCorrectCount + 1
%>
<font color="#008000">Correct answer</font>.<BR>
<%
          Else
             iCorrectAns = arr(7,j)
%>
<font color="#FF00000">Incorrect answer</font>. The correct answer is
no. <%=iCorrectAns%>:&nbsp;<%=arr(iCorrectAns+1,j)%>.<BR>
<%
          End If
       Next
   iTotal = Ubound(arr,2) + 1
%>
<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 %>


Marc
Author
10 Oct 2006 8:28 AM
Mike Brind
<marc_r_bertr***@hotmail.com> wrote in message
Show quoteHide quote
news:1160466178.301865.224660@i42g2000cwa.googlegroups.com...
> Mike Brind wrote:
>> <marc_r_bertr***@hotmail.com> wrote in message
>> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
>> 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
>> =============================================
>> <snip>
>>
>> <%
>>     For Each x in Request.Form
>>       Do While rst("iQuestID") <> CInt(x)
>>         rst.MoveNext
>>       Loop
>>       iCorrect = CInt(rst("iCorrectAns"))
>>       iChosen = CInt(Request.Form(x))
>> %>
>>
>>
>> At this point, it went into an infinite loop when I put on error resume
>> next
>> in.  The reason is that rst did try to go beyond EOF, because there is no
>> instruction for it to stop at EOF.
>>
>> You could try Do While rst("iQuestID") <> CInt(x) And Not rst.EOF
>>
>> The following should work, and makes use of GetRows, to save keeping the
>> recordset open for so long.  It also gets rid of the While... Wend loop
>> to
>> calculate the total number of questions:
>>
>> <%
>>
>>    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 Not rst.EOF Then arr = rst.GetRows
>>  rst.Close : Set rst = Nothing
>>  oCon.close : set oCon = nothing
>>
>>    If Request.Form.Count = 0 Then
>>       Call Quizpresent
>>    Else
>>       Call Quizscore
>>    End If
>>
>> Sub Quizpresent() %>
>> <% session("referer") = Request.ServerVariables("HTTP_REFERER") %>
>> <FORM METHOD="POST" ACTION="quiz.asp">
>> <OL>
>> <%If Isarray(arr) Then
>>  For a = 0 to Ubound(arr,2)
>> %>
>> <%= arr(0,a)%>&nbsp;&nbsp;<%=arr(1,a)%><BR>
>> <%
>>    Dim i
>>    Dim strChoice
>>    For i = 1 to 5
>>      strChoice = arr(i+1,a)
>>      If strChoice <> "" Then
>> %>
>> <INPUT TYPE="RADIO" NAME="<%=arr(0,a)%>" VALUE="<%=i%>">
>> <%=strChoice%>
>> <BR>
>> <%
>>      End If
>>    Next
>> %>
>> <BR>
>> <%
>> Next
>> %>
>> <br>
>> <br>
>> </OL>
>> <P><INPUT TYPE="SUBMIT" VALUE="Get Score">
>> <INPUT TYPE="RESET" VALUE="Clear All Answers">
>> </FORM>
>>
>> <%End If
>> 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
>>   j=0
>>        Do Until Cint(arr(0,j)) = CInt(x)
>>      j=j+1
>>        Loop
>>
>>       iCorrect = CInt(arr(7,j))
>>       iChosen = CInt(Request.Form(x))
>> %>
>> <P>
>> The question <%=arr(0,j)%> was:<%=arr(1,j) %><BR>
>> Your answer was:<%= iChosen %>.<BR>
>> <%
>>       If iChosen = iCorrect Then
>>           iCorrectCount = iCorrectCount + 1
>> %>
>> <font color="#008000">Correct answer</font>.<BR>
>> <%
>>       Else
>>    CorrectAnswer = arr(7,j)
>> %>
>> <font color="#FF00000">Incorrect answer</font>. The correct answer
>> is:<%=arr(CorrectAnswer+1,j)%>.<BR>
>> <%
>>       End If
>>    Next
>>      iTotal = Ubound(arr,2) + 1
>> %>
>> <br><br><hr><br>
>> <h4>Quiz statistics:</h4>
>> <br>
>> Number of questions:&nbsp;&nbsp;&nbsp;<%=iTotal%>
>> <br>
>> <%iAnswered=Request.Form.Count%>
>> <br>
>> Number of questions
>> answered:&nbsp;&nbsp;&nbsp;<%=iAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=FormatPercent(iAnswered/iTotal,0)%>
>>
>> <br>
>> <%iNotAnswered=iTotal-iAnswered%>
>> Number of questions not
>> answered:&nbsp;&nbsp;&nbsp;<%=iNotAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=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 %>
>>
>>
>> --
>> Mike Brind
>
> ===================================================================================
> Great!
> It works (after changing the Action attribute of the form tag that is
> :)). Now there is some serious progress. GetRows does it.
> Bloody recordset!
> I changed a few things in the stats area, just for aesthetic reasons.
> I like the idea of closing that recordset very quickly.
> Just one more thing: the Quizscore routine lists the questions in
> complete disorder.
>

It will do.  The Request.Form collection is not returned in any particular
order.  Since your loop is governed by the order in which the Request.Form
collection is passed (For each x in Request.Form) you don't have any
control.  You can acquire control by looping through the QuestIDs in the
array, then checking to see if there is a complementary x in the
Request.Form collection within that loop.  If there is, check to see if the
value is the right answer.  If not, move on.

--
Mike Brind
Author
10 Oct 2006 12:43 PM
marc_r_bertrand
Mike Brind wrote:
Show quoteHide quote
> <marc_r_bertr***@hotmail.com> wrote in message
> news:1160466178.301865.224660@i42g2000cwa.googlegroups.com...
> > Mike Brind wrote:
> >> <marc_r_bertr***@hotmail.com> wrote in message
> >> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
> >> 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
> >> =============================================
> >> <snip>
> >>
> >> <%
> >>     For Each x in Request.Form
> >>       Do While rst("iQuestID") <> CInt(x)
> >>         rst.MoveNext
> >>       Loop
> >>       iCorrect = CInt(rst("iCorrectAns"))
> >>       iChosen = CInt(Request.Form(x))
> >> %>
> >>
> >>
> >> At this point, it went into an infinite loop when I put on error resume
> >> next
> >> in.  The reason is that rst did try to go beyond EOF, because there is no
> >> instruction for it to stop at EOF.
> >>
> >> You could try Do While rst("iQuestID") <> CInt(x) And Not rst.EOF
> >>
> >> The following should work, and makes use of GetRows, to save keeping the
> >> recordset open for so long.  It also gets rid of the While... Wend loop
> >> to
> >> calculate the total number of questions:
> >>
> >> <%
> >>
> >>    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 Not rst.EOF Then arr = rst.GetRows
> >>  rst.Close : Set rst = Nothing
> >>  oCon.close : set oCon = nothing
> >>
> >>    If Request.Form.Count = 0 Then
> >>       Call Quizpresent
> >>    Else
> >>       Call Quizscore
> >>    End If
> >>
> >> Sub Quizpresent() %>
> >> <% session("referer") = Request.ServerVariables("HTTP_REFERER") %>
> >> <FORM METHOD="POST" ACTION="quiz.asp">
> >> <OL>
> >> <%If Isarray(arr) Then
> >>  For a = 0 to Ubound(arr,2)
> >> %>
> >> <%= arr(0,a)%>&nbsp;&nbsp;<%=arr(1,a)%><BR>
> >> <%
> >>    Dim i
> >>    Dim strChoice
> >>    For i = 1 to 5
> >>      strChoice = arr(i+1,a)
> >>      If strChoice <> "" Then
> >> %>
> >> <INPUT TYPE="RADIO" NAME="<%=arr(0,a)%>" VALUE="<%=i%>">
> >> <%=strChoice%>
> >> <BR>
> >> <%
> >>      End If
> >>    Next
> >> %>
> >> <BR>
> >> <%
> >> Next
> >> %>
> >> <br>
> >> <br>
> >> </OL>
> >> <P><INPUT TYPE="SUBMIT" VALUE="Get Score">
> >> <INPUT TYPE="RESET" VALUE="Clear All Answers">
> >> </FORM>
> >>
> >> <%End If
> >> 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
> >>   j=0
> >>        Do Until Cint(arr(0,j)) = CInt(x)
> >>      j=j+1
> >>        Loop
> >>
> >>       iCorrect = CInt(arr(7,j))
> >>       iChosen = CInt(Request.Form(x))
> >> %>
> >> <P>
> >> The question <%=arr(0,j)%> was:<%=arr(1,j) %><BR>
> >> Your answer was:<%= iChosen %>.<BR>
> >> <%
> >>       If iChosen = iCorrect Then
> >>           iCorrectCount = iCorrectCount + 1
> >> %>
> >> <font color="#008000">Correct answer</font>.<BR>
> >> <%
> >>       Else
> >>    CorrectAnswer = arr(7,j)
> >> %>
> >> <font color="#FF00000">Incorrect answer</font>. The correct answer
> >> is:<%=arr(CorrectAnswer+1,j)%>.<BR>
> >> <%
> >>       End If
> >>    Next
> >>      iTotal = Ubound(arr,2) + 1
> >> %>
> >> <br><br><hr><br>
> >> <h4>Quiz statistics:</h4>
> >> <br>
> >> Number of questions:&nbsp;&nbsp;&nbsp;<%=iTotal%>
> >> <br>
> >> <%iAnswered=Request.Form.Count%>
> >> <br>
> >> Number of questions
> >> answered:&nbsp;&nbsp;&nbsp;<%=iAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=FormatPercent(iAnswered/iTotal,0)%>
> >>
> >> <br>
> >> <%iNotAnswered=iTotal-iAnswered%>
> >> Number of questions not
> >> answered:&nbsp;&nbsp;&nbsp;<%=iNotAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=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 %>
> >>
> >>
> >> --
> >> Mike Brind
> >
> > ===================================================================================
> > Great!
> > It works (after changing the Action attribute of the form tag that is
> > :)). Now there is some serious progress. GetRows does it.
> > Bloody recordset!
> > I changed a few things in the stats area, just for aesthetic reasons.
> > I like the idea of closing that recordset very quickly.
> > Just one more thing: the Quizscore routine lists the questions in
> > complete disorder.
> >
>
> It will do.  The Request.Form collection is not returned in any particular
> order.  Since your loop is governed by the order in which the Request.Form
> collection is passed (For each x in Request.Form) you don't have any
> control.  You can acquire control by looping through the QuestIDs in the
> array, then checking to see if there is a complementary x in the
> Request.Form collection within that loop.  If there is, check to see if the
> value is the right answer.  If not, move on.
>
> --
> Mike Brind

==================================================================
Yes. I see. Did you mean something like this? It works.

<%
     For iID = 0 to UBound(arr,2)
            For Each x in Request.Form
    If CInt(x) = iID + 1 Then
              iCorrect = CInt(arr(7,iID))
              iChosen = CInt(Request.Form(x))
%>
<P>
                          Question <%=iID+1%> was:&nbsp;<%=arr(1, iID)
%><BR>
              Your answer was no. <% =iChosen %>:&nbsp;<%=
arr(iChosen+1,j) %>.<BR>
<%
                          If iChosen = iCorrect Then
                          iCorrectCount = iCorrectCount + 1
%>
                 <font color="#008000">Correct answer</font>.<BR>
<%
                          Else
                               iCorrectAns = arr(7,j)
%>
                              <font color="#FF00000">Incorrect
answer</font>. The correct answer is no.
<%=iCorrectAns%>:&nbsp;<%=arr(iCorrectAns+1,j)%>.<BR>
<%
              End If

        End If
               Next
        Next
Author
10 Oct 2006 1:10 PM
Mike Brind
<marc_r_bertr***@hotmail.com> wrote in message
news:1160484223.454048.287590@k70g2000cwa.googlegroups.com...
> Mike Brind wrote:
>> <marc_r_bertr***@hotmail.com> wrote in message
>> news:1160466178.301865.224660@i42g2000cwa.googlegroups.com...
>> > Mike Brind wrote:
>> >> <marc_r_bertr***@hotmail.com> wrote in message
>> >> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
>> >> To all asp/db pros:
>> >>

<snip>

Show quoteHide quote
>> > Great!
>> > It works (after changing the Action attribute of the form tag that is
>> > :)). Now there is some serious progress. GetRows does it.
>> > Bloody recordset!
>> > I changed a few things in the stats area, just for aesthetic reasons.
>> > I like the idea of closing that recordset very quickly.
>> > Just one more thing: the Quizscore routine lists the questions in
>> > complete disorder.
>> >
>>
>> It will do.  The Request.Form collection is not returned in any
>> particular
>> order.  Since your loop is governed by the order in which the
>> Request.Form
>> collection is passed (For each x in Request.Form) you don't have any
>> control.  You can acquire control by looping through the QuestIDs in the
>> array, then checking to see if there is a complementary x in the
>> Request.Form collection within that loop.  If there is, check to see if
>> the
>> value is the right answer.  If not, move on.
>>
>> --
>> Mike Brind
>
> ==================================================================
> Yes. I see. Did you mean something like this? It works.
>
> <%
>     For iID = 0 to UBound(arr,2)
>            For Each x in Request.Form
>  If CInt(x) = iID + 1 Then
>           iCorrect = CInt(arr(7,iID))
>           iChosen = CInt(Request.Form(x))
> %>

If it works, then yes - that's what I meant :-)

Just to tie up loose ends, the following is from your original, where it
broke:

<%
     For Each x in Request.Form
       Do While rst("iQuestID") <> CInt(x)
        rst.MoveNext
       Loop
       iCorrect = CInt(rst("iCorrectAns"))
       iChosen = CInt(Request.Form(x))
%>

This will work if the Request.Form collection is passed in numerical order,
and that may well have been the case when a small number of questions were
being answered.  What was actually happening was that if eg
Request.Form("32") was passed first, the Do While loop went through until
rst("iQuestID") = 32.  Then the code re-entered the For Each loop, with the
recordset cursor still pointing at 32.  Since the next x can't equal 32
(that's just been dealt with), the Movenext instruction moved the cursor to
33.  All well and good if the next x was indeed 33.  That would be handled
in the same way as 32, but this time leaving the cursor on rst("iQuestID")
=33.  You can see how this is going.  After that point, MoveNext will take
the cursor into the EOF region.  Basically the cursor needed to be reset at
the first record here:

<%
For Each x in Request.Form
       rst.MoveFirst
       Do While rst("iQuestID") <> CInt(x)
....
%>

I handled this with resetting j to 0 at the beginning of each loop, but the
way you've got it now makes a lot more sense.

--
Mike Brind
Author
10 Oct 2006 2:13 PM
marc_r_bertrand
Mike Brind wrote:
Show quoteHide quote
> <marc_r_bertr***@hotmail.com> wrote in message
> news:1160484223.454048.287590@k70g2000cwa.googlegroups.com...
> > Mike Brind wrote:
> >> <marc_r_bertr***@hotmail.com> wrote in message
> >> news:1160466178.301865.224660@i42g2000cwa.googlegroups.com...
> >> > Mike Brind wrote:
> >> >> <marc_r_bertr***@hotmail.com> wrote in message
> >> >> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
> >> >> To all asp/db pros:
> >> >>
>
> <snip>
>
> >> > Great!
> >> > It works (after changing the Action attribute of the form tag that is
> >> > :)). Now there is some serious progress. GetRows does it.
> >> > Bloody recordset!
> >> > I changed a few things in the stats area, just for aesthetic reasons.
> >> > I like the idea of closing that recordset very quickly.
> >> > Just one more thing: the Quizscore routine lists the questions in
> >> > complete disorder.
> >> >
> >>
> >> It will do.  The Request.Form collection is not returned in any
> >> particular
> >> order.  Since your loop is governed by the order in which the
> >> Request.Form
> >> collection is passed (For each x in Request.Form) you don't have any
> >> control.  You can acquire control by looping through the QuestIDs in the
> >> array, then checking to see if there is a complementary x in the
> >> Request.Form collection within that loop.  If there is, check to see if
> >> the
> >> value is the right answer.  If not, move on.
> >>
> >> --
> >> Mike Brind
> >
> > ==================================================================
> > Yes. I see. Did you mean something like this? It works.
> >
> > <%
> >     For iID = 0 to UBound(arr,2)
> >            For Each x in Request.Form
> >  If CInt(x) = iID + 1 Then
> >           iCorrect = CInt(arr(7,iID))
> >           iChosen = CInt(Request.Form(x))
> > %>
>
> If it works, then yes - that's what I meant :-)
>
> Just to tie up loose ends, the following is from your original, where it
> broke:
>
> <%
>      For Each x in Request.Form
>        Do While rst("iQuestID") <> CInt(x)
>         rst.MoveNext
>        Loop
>        iCorrect = CInt(rst("iCorrectAns"))
>        iChosen = CInt(Request.Form(x))
>  %>
>
> This will work if the Request.Form collection is passed in numerical order,
> and that may well have been the case when a small number of questions were
> being answered.  What was actually happening was that if eg
> Request.Form("32") was passed first, the Do While loop went through until
> rst("iQuestID") = 32.  Then the code re-entered the For Each loop, with the
> recordset cursor still pointing at 32.  Since the next x can't equal 32
> (that's just been dealt with), the Movenext instruction moved the cursor to
> 33.  All well and good if the next x was indeed 33.  That would be handled
> in the same way as 32, but this time leaving the cursor on rst("iQuestID")
> =33.  You can see how this is going.  After that point, MoveNext will take
> the cursor into the EOF region.  Basically the cursor needed to be reset at
> the first record here:
>
> <%
> For Each x in Request.Form
>        rst.MoveFirst
>        Do While rst("iQuestID") <> CInt(x)
> ...
> %>
>
> I handled this with resetting j to 0 at the beginning of each loop, but the
> way you've got it now makes a lot more sense.
>
> --
> Mike Brind

==================================================================
I was under the impression that the Form collection was passing things
that were in order to begin with...
Yes my last bit of code works, but it will work better with an
important mistake fixed:
The j in the line of code below is wrong:
Your answer was no. <% =iChosen %>:&nbsp;<%= arr(iChosen+1,,j) %>.<BR>
It should have been: iID instead of j
Your answer was no. <% =iChosen %>:&nbsp;<%= arr(iChosen+1,iID) %>.<BR>

Like you say. Ooops.

Finally, something else. When no question is answered, clicking the Get
Score button reloads the 'contained' file (the one we worked on with
the Subs) in the container file (the one first pointed at in the
browser). But this is similar to pointing at the contained file
directly, bypassing the first, and the html result is plain black on
white with no formatting from the calling file. That's not good.
How would you code: if the quiz questions are already there (file has
been loaded once) and none of the questions has been answered, don't
call Quizpresent. Right now, Quizpresent is called because
Request.Form.Count = 0 (none of the questions has been answered).
What's missing I think is the first part: if the quiz questions are
already there... Am I correct?

This is what we have now:

   If Request.Form.Count = 0 Then
      Call Quizpresent
   Else
      Call Quizscore
   End If
Author
10 Oct 2006 2:56 PM
Mike Brind
<marc_r_bertr***@hotmail.com> wrote in message
Show quoteHide quote
news:1160489608.970239.7940@m73g2000cwd.googlegroups.com...
>
> Mike Brind wrote:
>> <marc_r_bertr***@hotmail.com> wrote in message
>> news:1160484223.454048.287590@k70g2000cwa.googlegroups.com...
>> > Mike Brind wrote:
>> >> <marc_r_bertr***@hotmail.com> wrote in message
>> >> news:1160466178.301865.224660@i42g2000cwa.googlegroups.com...
>> >> > Mike Brind wrote:
>> >> >> <marc_r_bertr***@hotmail.com> wrote in message
>> >> >> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
>> >> >> To all asp/db pros:
>> >> >>
>>
>> <snip>
>>
>> >> > Great!
>> >> > It works (after changing the Action attribute of the form tag that
>> >> > is
>> >> > :)). Now there is some serious progress. GetRows does it.
>> >> > Bloody recordset!
>> >> > I changed a few things in the stats area, just for aesthetic
>> >> > reasons.
>> >> > I like the idea of closing that recordset very quickly.
>> >> > Just one more thing: the Quizscore routine lists the questions in
>> >> > complete disorder.
>> >> >
>> >>
>> >> It will do.  The Request.Form collection is not returned in any
>> >> particular
>> >> order.  Since your loop is governed by the order in which the
>> >> Request.Form
>> >> collection is passed (For each x in Request.Form) you don't have any
>> >> control.  You can acquire control by looping through the QuestIDs in
>> >> the
>> >> array, then checking to see if there is a complementary x in the
>> >> Request.Form collection within that loop.  If there is, check to see
>> >> if
>> >> the
>> >> value is the right answer.  If not, move on.
>> >>
>> >> --
>> >> Mike Brind
>> >
>> > ==================================================================
>> > Yes. I see. Did you mean something like this? It works.
>> >
>> > <%
>> >     For iID = 0 to UBound(arr,2)
>> >            For Each x in Request.Form
>> >  If CInt(x) = iID + 1 Then
>> >           iCorrect = CInt(arr(7,iID))
>> >           iChosen = CInt(Request.Form(x))
>> > %>
>>
>> If it works, then yes - that's what I meant :-)
>>
>> Just to tie up loose ends, the following is from your original, where it
>> broke:
>>
>> <%
>>      For Each x in Request.Form
>>        Do While rst("iQuestID") <> CInt(x)
>>         rst.MoveNext
>>        Loop
>>        iCorrect = CInt(rst("iCorrectAns"))
>>        iChosen = CInt(Request.Form(x))
>>  %>
>>
>> This will work if the Request.Form collection is passed in numerical
>> order,
>> and that may well have been the case when a small number of questions
>> were
>> being answered.  What was actually happening was that if eg
>> Request.Form("32") was passed first, the Do While loop went through until
>> rst("iQuestID") = 32.  Then the code re-entered the For Each loop, with
>> the
>> recordset cursor still pointing at 32.  Since the next x can't equal 32
>> (that's just been dealt with), the Movenext instruction moved the cursor
>> to
>> 33.  All well and good if the next x was indeed 33.  That would be
>> handled
>> in the same way as 32, but this time leaving the cursor on
>> rst("iQuestID")
>> =33.  You can see how this is going.  After that point, MoveNext will
>> take
>> the cursor into the EOF region.  Basically the cursor needed to be reset
>> at
>> the first record here:
>>
>> <%
>> For Each x in Request.Form
>>        rst.MoveFirst
>>        Do While rst("iQuestID") <> CInt(x)
>> ...
>> %>
>>
>> I handled this with resetting j to 0 at the beginning of each loop, but
>> the
>> way you've got it now makes a lot more sense.
>>
>> --
>> Mike Brind
>
> ==================================================================
> I was under the impression that the Form collection was passing things
> that were in order to begin with...
> Yes my last bit of code works, but it will work better with an
> important mistake fixed:
> The j in the line of code below is wrong:
> Your answer was no. <% =iChosen %>:&nbsp;<%= arr(iChosen+1,,j) %>.<BR>
> It should have been: iID instead of j
> Your answer was no. <% =iChosen %>:&nbsp;<%= arr(iChosen+1,iID) %>.<BR>
>
> Like you say. Ooops.
>
> Finally, something else. When no question is answered, clicking the Get
> Score button reloads the 'contained' file (the one we worked on with
> the Subs) in the container file (the one first pointed at in the
> browser). But this is similar to pointing at the contained file
> directly, bypassing the first, and the html result is plain black on
> white with no formatting from the calling file. That's not good.
> How would you code: if the quiz questions are already there (file has
> been loaded once) and none of the questions has been answered, don't
> call Quizpresent.
> Right now, Quizpresent is called because
> Request.Form.Count = 0 (none of the questions has been answered).
> What's missing I think is the first part: if the quiz questions are
> already there... Am I correct?
>
> This is what we have now:
>
>   If Request.Form.Count = 0 Then
>      Call Quizpresent
>   Else
>      Call Quizscore
>   End If
>

Try changing it to run QuizScore if the submit button is not present in the
Form collection.  You would then have to give the submit button a name
attribute (which it should have anyway):

<INPUT TYPE="SUBMIT" NAME="SomeName" VALUE="Get Score">

But then you would have to exclude Request.Form("SomeName") from the loop
where it gets compared to the QuestID.  Trying to convert "SomeName"  to an
int will definitely cause an error.
..
If Request.Form("SomeName")<>"Get Score" Then
     Call Quizpresent
  Else
     Call Quizscore
End If


--
Mike Brind
Author
10 Oct 2006 3:29 PM
marc_r_bertrand
Mike Brind wrote:
Show quoteHide quote
> <marc_r_bertr***@hotmail.com> wrote in message
> news:1160489608.970239.7940@m73g2000cwd.googlegroups.com...
> >
> > Mike Brind wrote:
> >> <marc_r_bertr***@hotmail.com> wrote in message
> >> news:1160484223.454048.287590@k70g2000cwa.googlegroups.com...
> >> > Mike Brind wrote:
> >> >> <marc_r_bertr***@hotmail.com> wrote in message
> >> >> news:1160466178.301865.224660@i42g2000cwa.googlegroups.com...
> >> >> > Mike Brind wrote:
> >> >> >> <marc_r_bertr***@hotmail.com> wrote in message
> >> >> >> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
> >> >> >> To all asp/db pros:
> >> >> >>
> >>
> >> <snip>
> >>
> >> >> > Great!
> >> >> > It works (after changing the Action attribute of the form tag that
> >> >> > is
> >> >> > :)). Now there is some serious progress. GetRows does it.
> >> >> > Bloody recordset!
> >> >> > I changed a few things in the stats area, just for aesthetic
> >> >> > reasons.
> >> >> > I like the idea of closing that recordset very quickly.
> >> >> > Just one more thing: the Quizscore routine lists the questions in
> >> >> > complete disorder.
> >> >> >
> >> >>
> >> >> It will do.  The Request.Form collection is not returned in any
> >> >> particular
> >> >> order.  Since your loop is governed by the order in which the
> >> >> Request.Form
> >> >> collection is passed (For each x in Request.Form) you don't have any
> >> >> control.  You can acquire control by looping through the QuestIDs in
> >> >> the
> >> >> array, then checking to see if there is a complementary x in the
> >> >> Request.Form collection within that loop.  If there is, check to see
> >> >> if
> >> >> the
> >> >> value is the right answer.  If not, move on.
> >> >>
> >> >> --
> >> >> Mike Brind
> >> >
> >> > ==================================================================
> >> > Yes. I see. Did you mean something like this? It works.
> >> >
> >> > <%
> >> >     For iID = 0 to UBound(arr,2)
> >> >            For Each x in Request.Form
> >> >  If CInt(x) = iID + 1 Then
> >> >           iCorrect = CInt(arr(7,iID))
> >> >           iChosen = CInt(Request.Form(x))
> >> > %>
> >>
> >> If it works, then yes - that's what I meant :-)
> >>
> >> Just to tie up loose ends, the following is from your original, where it
> >> broke:
> >>
> >> <%
> >>      For Each x in Request.Form
> >>        Do While rst("iQuestID") <> CInt(x)
> >>         rst.MoveNext
> >>        Loop
> >>        iCorrect = CInt(rst("iCorrectAns"))
> >>        iChosen = CInt(Request.Form(x))
> >>  %>
> >>
> >> This will work if the Request.Form collection is passed in numerical
> >> order,
> >> and that may well have been the case when a small number of questions
> >> were
> >> being answered.  What was actually happening was that if eg
> >> Request.Form("32") was passed first, the Do While loop went through until
> >> rst("iQuestID") = 32.  Then the code re-entered the For Each loop, with
> >> the
> >> recordset cursor still pointing at 32.  Since the next x can't equal 32
> >> (that's just been dealt with), the Movenext instruction moved the cursor
> >> to
> >> 33.  All well and good if the next x was indeed 33.  That would be
> >> handled
> >> in the same way as 32, but this time leaving the cursor on
> >> rst("iQuestID")
> >> =33.  You can see how this is going.  After that point, MoveNext will
> >> take
> >> the cursor into the EOF region.  Basically the cursor needed to be reset
> >> at
> >> the first record here:
> >>
> >> <%
> >> For Each x in Request.Form
> >>        rst.MoveFirst
> >>        Do While rst("iQuestID") <> CInt(x)
> >> ...
> >> %>
> >>
> >> I handled this with resetting j to 0 at the beginning of each loop, but
> >> the
> >> way you've got it now makes a lot more sense.
> >>
> >> --
> >> Mike Brind
> >
> > ==================================================================
> > I was under the impression that the Form collection was passing things
> > that were in order to begin with...
> > Yes my last bit of code works, but it will work better with an
> > important mistake fixed:
> > The j in the line of code below is wrong:
> > Your answer was no. <% =iChosen %>:&nbsp;<%= arr(iChosen+1,,j) %>.<BR>
> > It should have been: iID instead of j
> > Your answer was no. <% =iChosen %>:&nbsp;<%= arr(iChosen+1,iID) %>.<BR>
> >
> > Like you say. Ooops.
> >
> > Finally, something else. When no question is answered, clicking the Get
> > Score button reloads the 'contained' file (the one we worked on with
> > the Subs) in the container file (the one first pointed at in the
> > browser). But this is similar to pointing at the contained file
> > directly, bypassing the first, and the html result is plain black on
> > white with no formatting from the calling file. That's not good.
> > How would you code: if the quiz questions are already there (file has
> > been loaded once) and none of the questions has been answered, don't
> > call Quizpresent.
> > Right now, Quizpresent is called because
> > Request.Form.Count = 0 (none of the questions has been answered).
> > What's missing I think is the first part: if the quiz questions are
> > already there... Am I correct?
> >
> > This is what we have now:
> >
> >   If Request.Form.Count = 0 Then
> >      Call Quizpresent
> >   Else
> >      Call Quizscore
> >   End If
> >
>
> Try changing it to run QuizScore if the submit button is not present in the
> Form collection.  You would then have to give the submit button a name
> attribute (which it should have anyway):
>
> <INPUT TYPE="SUBMIT" NAME="SomeName" VALUE="Get Score">
>
> But then you would have to exclude Request.Form("SomeName") from the loop
> where it gets compared to the QuestID.  Trying to convert "SomeName"  to an
> int will definitely cause an error.
> .
> If Request.Form("SomeName")<>"Get Score" Then
>      Call Quizpresent
>   Else
>      Call Quizscore
>  End If
>
>
> --
> Mike Brind

===========================================================
I tried it. I gave a name to the Submit button (SUBMITBUTTON) and to
the Reset button (RESETBUTTON).
The problem is that with no option button clicked, clicking only the
Get Score button at the bottom still shows the results page anyway with
nothing in the Results section and the stats as if the test had been
taken (QuizScore is run). It would be best if the result page did not
show at all, as if nothing happened when the Get Score button is
clicked.

For iID = 0 to UBound(arr,2)
       For Each x in Request.Form
        If x <> "SUBMITBUTTON" And x <> "RESETBUTTON" Then

Marc
Author
10 Oct 2006 3:49 PM
Mike Brind
<marc_r_bertr***@hotmail.com> wrote in message
Show quoteHide quote
news:1160494197.697676.198720@c28g2000cwb.googlegroups.com...
>
> Mike Brind wrote:
>> <marc_r_bertr***@hotmail.com> wrote in message
>> news:1160489608.970239.7940@m73g2000cwd.googlegroups.com...
>> >
>> > Mike Brind wrote:
>> >> <marc_r_bertr***@hotmail.com> wrote in message
>> >> news:1160484223.454048.287590@k70g2000cwa.googlegroups.com...
>> >> > Mike Brind wrote:
>> >> >> <marc_r_bertr***@hotmail.com> wrote in message
>> >> >> news:1160466178.301865.224660@i42g2000cwa.googlegroups.com...
>> >> >> > Mike Brind wrote:
>> >> >> >> <marc_r_bertr***@hotmail.com> wrote in message
>> >> >> >> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
>> >> >> >> To all asp/db pros:
>> >> >> >>
>> >>
>> >> <snip>
>> >>
>> >> >> > Great!
>> >> >> > It works (after changing the Action attribute of the form tag
>> >> >> > that
>> >> >> > is
>> >> >> > :)). Now there is some serious progress. GetRows does it.
>> >> >> > Bloody recordset!
>> >> >> > I changed a few things in the stats area, just for aesthetic
>> >> >> > reasons.
>> >> >> > I like the idea of closing that recordset very quickly.
>> >> >> > Just one more thing: the Quizscore routine lists the questions in
>> >> >> > complete disorder.
>> >> >> >
>> >> >>
>> >> >> It will do.  The Request.Form collection is not returned in any
>> >> >> particular
>> >> >> order.  Since your loop is governed by the order in which the
>> >> >> Request.Form
>> >> >> collection is passed (For each x in Request.Form) you don't have
>> >> >> any
>> >> >> control.  You can acquire control by looping through the QuestIDs
>> >> >> in
>> >> >> the
>> >> >> array, then checking to see if there is a complementary x in the
>> >> >> Request.Form collection within that loop.  If there is, check to
>> >> >> see
>> >> >> if
>> >> >> the
>> >> >> value is the right answer.  If not, move on.
>> >> >>
>> >> >> --
>> >> >> Mike Brind
>> >> >
>> >> > ==================================================================
>> >> > Yes. I see. Did you mean something like this? It works.
>> >> >
>> >> > <%
>> >> >     For iID = 0 to UBound(arr,2)
>> >> >            For Each x in Request.Form
>> >> >  If CInt(x) = iID + 1 Then
>> >> >           iCorrect = CInt(arr(7,iID))
>> >> >           iChosen = CInt(Request.Form(x))
>> >> > %>
>> >>
>> >> If it works, then yes - that's what I meant :-)
>> >>
>> >> Just to tie up loose ends, the following is from your original, where
>> >> it
>> >> broke:
>> >>
>> >> <%
>> >>      For Each x in Request.Form
>> >>        Do While rst("iQuestID") <> CInt(x)
>> >>         rst.MoveNext
>> >>        Loop
>> >>        iCorrect = CInt(rst("iCorrectAns"))
>> >>        iChosen = CInt(Request.Form(x))
>> >>  %>
>> >>
>> >> This will work if the Request.Form collection is passed in numerical
>> >> order,
>> >> and that may well have been the case when a small number of questions
>> >> were
>> >> being answered.  What was actually happening was that if eg
>> >> Request.Form("32") was passed first, the Do While loop went through
>> >> until
>> >> rst("iQuestID") = 32.  Then the code re-entered the For Each loop,
>> >> with
>> >> the
>> >> recordset cursor still pointing at 32.  Since the next x can't equal
>> >> 32
>> >> (that's just been dealt with), the Movenext instruction moved the
>> >> cursor
>> >> to
>> >> 33.  All well and good if the next x was indeed 33.  That would be
>> >> handled
>> >> in the same way as 32, but this time leaving the cursor on
>> >> rst("iQuestID")
>> >> =33.  You can see how this is going.  After that point, MoveNext will
>> >> take
>> >> the cursor into the EOF region.  Basically the cursor needed to be
>> >> reset
>> >> at
>> >> the first record here:
>> >>
>> >> <%
>> >> For Each x in Request.Form
>> >>        rst.MoveFirst
>> >>        Do While rst("iQuestID") <> CInt(x)
>> >> ...
>> >> %>
>> >>
>> >> I handled this with resetting j to 0 at the beginning of each loop,
>> >> but
>> >> the
>> >> way you've got it now makes a lot more sense.
>> >>
>> >> --
>> >> Mike Brind
>> >
>> > ==================================================================
>> > I was under the impression that the Form collection was passing things
>> > that were in order to begin with...
>> > Yes my last bit of code works, but it will work better with an
>> > important mistake fixed:
>> > The j in the line of code below is wrong:
>> > Your answer was no. <% =iChosen %>:&nbsp;<%= arr(iChosen+1,,j) %>.<BR>
>> > It should have been: iID instead of j
>> > Your answer was no. <% =iChosen %>:&nbsp;<%= arr(iChosen+1,iID) %>.<BR>
>> >
>> > Like you say. Ooops.
>> >
>> > Finally, something else. When no question is answered, clicking the Get
>> > Score button reloads the 'contained' file (the one we worked on with
>> > the Subs) in the container file (the one first pointed at in the
>> > browser). But this is similar to pointing at the contained file
>> > directly, bypassing the first, and the html result is plain black on
>> > white with no formatting from the calling file. That's not good.
>> > How would you code: if the quiz questions are already there (file has
>> > been loaded once) and none of the questions has been answered, don't
>> > call Quizpresent.
>> > Right now, Quizpresent is called because
>> > Request.Form.Count = 0 (none of the questions has been answered).
>> > What's missing I think is the first part: if the quiz questions are
>> > already there... Am I correct?
>> >
>> > This is what we have now:
>> >
>> >   If Request.Form.Count = 0 Then
>> >      Call Quizpresent
>> >   Else
>> >      Call Quizscore
>> >   End If
>> >
>>
>> Try changing it to run QuizScore if the submit button is not present in
>> the
>> Form collection.  You would then have to give the submit button a name
>> attribute (which it should have anyway):
>>
>> <INPUT TYPE="SUBMIT" NAME="SomeName" VALUE="Get Score">
>>
>> But then you would have to exclude Request.Form("SomeName") from the loop
>> where it gets compared to the QuestID.  Trying to convert "SomeName"  to
>> an
>> int will definitely cause an error.
>> .
>> If Request.Form("SomeName")<>"Get Score" Then
>>      Call Quizpresent
>>   Else
>>      Call Quizscore
>>  End If
>>
>>
>> --
>> Mike Brind
>
> ===========================================================
> I tried it. I gave a name to the Submit button (SUBMITBUTTON) and to
> the Reset button (RESETBUTTON).
> The problem is that with no option button clicked, clicking only the
> Get Score button at the bottom still shows the results page anyway with
> nothing in the Results section and the stats as if the test had been
> taken (QuizScore is run). It would be best if the result page did not
> show at all, as if nothing happened when the Get Score button is
> clicked.
>
> For iID = 0 to UBound(arr,2)
>       For Each x in Request.Form
>    If x <> "SUBMITBUTTON" And x <> "RESETBUTTON" Then
>
> Marc
>

In that case, if Request.Form.Count>1 they must have answered at least one
question.  If it =1, they submitted the form only.  You don't need to
include the reset button.  That doesn't get passed.  All it does is clear
the form contents.

--
Mike Brind
Author
10 Oct 2006 2:38 PM
marc_r_bertrand
marc_r_bertr***@hotmail.com wrote:
Show quoteHide quote
> Mike Brind wrote:
> > <marc_r_bertr***@hotmail.com> wrote in message
> > news:1160466178.301865.224660@i42g2000cwa.googlegroups.com...
> > > Mike Brind wrote:
> > >> <marc_r_bertr***@hotmail.com> wrote in message
> > >> news:1160305922.281892.297800@e3g2000cwe.googlegroups.com...
> > >> 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
> > >> =============================================
> > >> <snip>
> > >>
> > >> <%
> > >>     For Each x in Request.Form
> > >>       Do While rst("iQuestID") <> CInt(x)
> > >>         rst.MoveNext
> > >>       Loop
> > >>       iCorrect = CInt(rst("iCorrectAns"))
> > >>       iChosen = CInt(Request.Form(x))
> > >> %>
> > >>
> > >>
> > >> At this point, it went into an infinite loop when I put on error resume
> > >> next
> > >> in.  The reason is that rst did try to go beyond EOF, because there is no
> > >> instruction for it to stop at EOF.
> > >>
> > >> You could try Do While rst("iQuestID") <> CInt(x) And Not rst.EOF
> > >>
> > >> The following should work, and makes use of GetRows, to save keeping the
> > >> recordset open for so long.  It also gets rid of the While... Wend loop
> > >> to
> > >> calculate the total number of questions:
> > >>
> > >> <%
> > >>
> > >>    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 Not rst.EOF Then arr = rst.GetRows
> > >>  rst.Close : Set rst = Nothing
> > >>  oCon.close : set oCon = nothing
> > >>
> > >>    If Request.Form.Count = 0 Then
> > >>       Call Quizpresent
> > >>    Else
> > >>       Call Quizscore
> > >>    End If
> > >>
> > >> Sub Quizpresent() %>
> > >> <% session("referer") = Request.ServerVariables("HTTP_REFERER") %>
> > >> <FORM METHOD="POST" ACTION="quiz.asp">
> > >> <OL>
> > >> <%If Isarray(arr) Then
> > >>  For a = 0 to Ubound(arr,2)
> > >> %>
> > >> <%= arr(0,a)%>&nbsp;&nbsp;<%=arr(1,a)%><BR>
> > >> <%
> > >>    Dim i
> > >>    Dim strChoice
> > >>    For i = 1 to 5
> > >>      strChoice = arr(i+1,a)
> > >>      If strChoice <> "" Then
> > >> %>
> > >> <INPUT TYPE="RADIO" NAME="<%=arr(0,a)%>" VALUE="<%=i%>">
> > >> <%=strChoice%>
> > >> <BR>
> > >> <%
> > >>      End If
> > >>    Next
> > >> %>
> > >> <BR>
> > >> <%
> > >> Next
> > >> %>
> > >> <br>
> > >> <br>
> > >> </OL>
> > >> <P><INPUT TYPE="SUBMIT" VALUE="Get Score">
> > >> <INPUT TYPE="RESET" VALUE="Clear All Answers">
> > >> </FORM>
> > >>
> > >> <%End If
> > >> 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
> > >>   j=0
> > >>        Do Until Cint(arr(0,j)) = CInt(x)
> > >>      j=j+1
> > >>        Loop
> > >>
> > >>       iCorrect = CInt(arr(7,j))
> > >>       iChosen = CInt(Request.Form(x))
> > >> %>
> > >> <P>
> > >> The question <%=arr(0,j)%> was:<%=arr(1,j) %><BR>
> > >> Your answer was:<%= iChosen %>.<BR>
> > >> <%
> > >>       If iChosen = iCorrect Then
> > >>           iCorrectCount = iCorrectCount + 1
> > >> %>
> > >> <font color="#008000">Correct answer</font>.<BR>
> > >> <%
> > >>       Else
> > >>    CorrectAnswer = arr(7,j)
> > >> %>
> > >> <font color="#FF00000">Incorrect answer</font>. The correct answer
> > >> is:<%=arr(CorrectAnswer+1,j)%>.<BR>
> > >> <%
> > >>       End If
> > >>    Next
> > >>      iTotal = Ubound(arr,2) + 1
> > >> %>
> > >> <br><br><hr><br>
> > >> <h4>Quiz statistics:</h4>
> > >> <br>
> > >> Number of questions:&nbsp;&nbsp;&nbsp;<%=iTotal%>
> > >> <br>
> > >> <%iAnswered=Request.Form.Count%>
> > >> <br>
> > >> Number of questions
> > >> answered:&nbsp;&nbsp;&nbsp;<%=iAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=FormatPercent(iAnswered/iTotal,0)%>
> > >>
> > >> <br>
> > >> <%iNotAnswered=iTotal-iAnswered%>
> > >> Number of questions not
> > >> answered:&nbsp;&nbsp;&nbsp;<%=iNotAnswered%>&nbsp;&nbsp;or&nbsp;&nbsp;<%=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 %>
> > >>
> > >>
> > >> --
> > >> Mike Brind
> > >
> > > ===================================================================================
> > > Great!
> > > It works (after changing the Action attribute of the form tag that is
> > > :)). Now there is some serious progress. GetRows does it.
> > > Bloody recordset!
> > > I changed a few things in the stats area, just for aesthetic reasons.
> > > I like the idea of closing that recordset very quickly.
> > > Just one more thing: the Quizscore routine lists the questions in
> > > complete disorder.
> > >
> >
> > It will do.  The Request.Form collection is not returned in any particular
> > order.  Since your loop is governed by the order in which the Request.Form
> > collection is passed (For each x in Request.Form) you don't have any
> > control.  You can acquire control by looping through the QuestIDs in the
> > array, then checking to see if there is a complementary x in the
> > Request.Form collection within that loop.  If there is, check to see if the
> > value is the right answer.  If not, move on.
> >
> > --
> > Mike Brind
>
> ==================================================================
> Yes. I see. Did you mean something like this? It works.
>
> <%
>      For iID = 0 to UBound(arr,2)
>             For Each x in Request.Form
>      If CInt(x) = iID + 1 Then
>               iCorrect = CInt(arr(7,iID))
>               iChosen = CInt(Request.Form(x))
> %>
> <P>
>                           Question <%=iID+1%> was:&nbsp;<%=arr(1, iID)
> %><BR>
>               Your answer was no. <% =iChosen %>:&nbsp;<%=
> arr(iChosen+1,j) %>.<BR>
> <%
>                           If iChosen = iCorrect Then
>                           iCorrectCount = iCorrectCount + 1
> %>
>                  <font color="#008000">Correct answer</font>.<BR>
> <%
>                           Else
>                                iCorrectAns = arr(7,j)
> %>
>                               <font color="#FF00000">Incorrect
> answer</font>. The correct answer is no.
> <%=iCorrectAns%>:&nbsp;<%=arr(iCorrectAns+1,j)%>.<BR>
> <%
>               End If
>
>         End If
>                Next
>         Next
------------------------------------------------------------------------------------------------------------------------------
This is better. I'll get there...

<%
    For iID = 0 to UBound(arr,2)
            For Each x in Request.Form
        If CInt(x) = iID + 1 Then
              iCorrect = CInt(arr(7,iID))
              iChosen = CInt(Request.Form(x))

%>
<P>
          Question <%=iID+1%> was:&nbsp;<%=arr(1, iID) %><BR>
          Your answer was no. <% =iChosen %>:&nbsp;<%= arr(iChosen+1,iID)
%>.<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 no.
<%=iCorrect%>:&nbsp;<%=arr(iCorrect+1,iID)%>.<BR>
<%
              End If

        End If
        Next
        Next


   iTotal = Ubound(arr,2) + 1
%>

Bookmark and Share