473,383 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Quizz script performance bug -- too many questions?

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;&nb sp;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(iNotAnswe red/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 %>
================================================== ============

Oct 8 '06 #1
16 1695

<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.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;&nb sp;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(iNotAnswe red/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
Oct 8 '06 #2

Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.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;&nb sp;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(iNotAnswe red/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.

Oct 9 '06 #3
<ma*************@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...

Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.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;&nb sp;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(iNotAnswe red/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
Oct 9 '06 #4
"Mike Brind" <pa*******@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
<ma*************@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...

Mike Brind wrote:
><ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegr oups.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;&n bsp;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(iNotAnswere d/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...
Oct 9 '06 #5
Mike Brind wrote:
"Mike Brind" <pa*******@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
<ma*************@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...

Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.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;&nb sp;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(iNotAnswe red/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

================================================== ==================================

Oct 9 '06 #6
Mike Brind wrote:
"Mike Brind" <pa*******@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
<ma*************@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...

Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.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;&nb sp;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(iNotAnswe red/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%

Oct 9 '06 #7

<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.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;&nb sp;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(iNotAnswer ed/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
Oct 9 '06 #8
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.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;&nb sp;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(iNotAnswer ed/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

Oct 10 '06 #9
<ma*************@hotmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Mike Brind wrote:
><ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegr oups.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;&n bsp;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(iNotAnswer ed/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
Oct 10 '06 #10
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.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;&nb sp;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(iNotAnswer ed/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

Oct 10 '06 #11
<ma*************@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Mike Brind wrote:
><ma*************@hotmail.comwrote in message
news:11**********************@i42g2000cwa.googleg roups.com...
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegr oups.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
Oct 10 '06 #12

Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.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

Oct 10 '06 #13

ma*************@hotmail.com wrote:
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Mike Brind wrote:
><ma*************@hotmail.comwrote in message
>news:11**********************@e3g2000cwe.googlegr oups.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;&n bsp;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(iNotAnswer ed/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
%>

Oct 10 '06 #14
<ma*************@hotmail.comwrote in message
news:11********************@m73g2000cwd.googlegrou ps.com...
>
Mike Brind wrote:
><ma*************@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googleg roups.com...
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@i42g2000cwa.googleg roups.com...
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegr oups.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
Oct 10 '06 #15

Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11********************@m73g2000cwd.googlegrou ps.com...

Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.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

Oct 10 '06 #16
<ma*************@hotmail.comwrote in message
news:11**********************@c28g2000cwb.googlegr oups.com...
>
Mike Brind wrote:
><ma*************@hotmail.comwrote in message
news:11********************@m73g2000cwd.googlegro ups.com...
>
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googleg roups.com...
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@i42g2000cwa.googleg roups.com...
Mike Brind wrote:
<ma*************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegr oups.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
Oct 10 '06 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Brian Patterson | last post by:
I have noticed in the book of words that hasattr works by calling getattr and raising an exception if no such attribute exists. If I need the value in any case, am I better off using getattr...
5
by: Tlo | last post by:
hello, i would like to do the following, and as i had never used python in a network framework i would like to have opinions on this : i would like to provide some kind of network quizz game,...
3
by: Andy Dingley | last post by:
I've just started on a new project and inherited a huge pile of XSLT (and I use the term "pile" advisedly !) It runs at glacial speed, and I need to fix this this. Platform is MSXML 4 / ASP ...
10
by: **ham | last post by:
I know that's an old dirty issue; GDI+ almost -the slowest part of the framework - has bothered many developers using it in animations. Even in managed C++ the performance is awful. Now, any dude...
14
by: Rich | last post by:
I have a project that I would Greatly Appreciate some direction. My goal is to create a "Sales Assistant Script" that recommends products based upon Response's to questions. I know enough...
11
by: ZenRhapsody | last post by:
Has anyone done any performance testing between new generic Lists and single dimensional arrays? I really like the code flexibility the List provides since I don't know how many items I will...
5
by: Markus Ernst | last post by:
Hello A class that composes the output of shop-related data gets some info from the main shop class. Now I wonder whether it is faster to store the info in the output class or get it from the...
2
by: jodleren | last post by:
Hi! I want to create a quizz, where a page loads the questions (currently in HTML), and them, when the user answers, it will count a "total", and a "right" or "Wrong", eventually along with some...
5
by: pantagruel | last post by:
Hi, It is generally stated that stringbuilder should be used instead of just concatenating strings with the plus operator. That's fine enough what I'm wondering in cases I have: String S =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.