Quizz脚本性能错误 - 问题太多了? [英] Quizz script performance bug -- too many questions?
问题描述
致所有asp / db专业人士:
以下测验代码有效。但是,当答案太多(单击单选按钮)时,会出现问题。我不是一个asp专业人士。
那么,是否有专业人士或业余专家会如此善良,以便志愿者花一些时间来弄清楚bug是?这可能意味着他将需要经历繁琐的步骤来创建一个带有
几条记录的.mdb ...除非这个bug很明显......
在一个包含服务器代码生成单选按钮的页面上(测验格式从1
到最多5个答案),有一个提交按钮。点击此按钮后,页面会显示答案和其他统计信息。问题是
只有当问题的答案超过一定数量时才会经常出现同样的错误,具体取决于哪些问题
回答,从下往上或从上到下等等...如果
小于,比如,回答了六个问题,则没有错误。
去图...
给出错误的行是:执行rst(" iQuestID")< CInt(x)
这一行在For Quizscore()中,在For Each循环中。
错误:
======== ====================================
错误类型:
(0x80020009)
发生异常。
/AllQuizzes/xlGenGeneral.asp,第76行
Mozilla / 4.0(兼容; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322)
页:
POST 60个字节到/AllQuizzes/xlGenGeneral.asp
POST数据:
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")
设置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
致电Quizscore
结束如果
oCon.close
set oCon = nothing
%>
<%Sub Quizpresent()%>
<%session(" referer")= Request.ServerVariables(" HTTP_REFERER")% >
< FORM METHOD =" POST&qu OT; ACTION =" xlGenGeneral.asp">
< OL>
<%Do not whilerst.EOF%>
<%= RST(" iQuestID")%>&安培; NBSP;&安培; NBSP;<%= RST(" mQuest")%> < BR>
<%
Dim i
Dim strChoice
i = 1到5
strChoice = rst.fields(i + 1).value
如果strChoice<""然后
%>
< INPUT TYPE =" RADIO" NAME ="<%= RST(" iQuestID")%>" VALUE ="<%= i%>">
<%= strChoice%>
< BR>
<%
结束如果
下一页
%>
< BR>
<%
rst.MoveNext
Loop
rst.MoveFirst
%>
< br>
< br>
< / OL>
< P>< ; INPUT TYPE =" SUBMIT" VALUE =获得分数>
< INPUT TYPE =" RESET" VALUE =" Clear All Answers"
< / FORM>
<%End Sub%>
<%
Sub Quizscore()
Dim x
Dim iTotal
Dim iAnswers
Dim iNotAtwered
Dim iCorrect
Dim iCorrectCount
Dim iChosen
iTotal = 0
icorrectCount = 0
%>
< HTML>
< BODY BGCOLOR =" #fffff">
< font size =" 2" face =" Arial">
< h4>测验结果:< / h4>
<%
每个x在Request.Form
做rst(" iQuestID")< CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst(" iCorrectAns"))
iChosen = CInt(Request.Form(x))
%>
< P>
问题<%= rst(" iQuestID")%>为:<%= rst(" mQuest")%>< BR>
您的回答是:<%= rst.fields(iChosen + 1).value%>。< BR>
<%
如果iChosen = iCorrect那么
iCorrectCount = iCorrectCount + 1
%>
< font color ="# 008000">正确答案< / font>。< BR>
<%
否则
%>
< font color ="#FF00000">错误答案< / font>。正确的答案
是:<%= rst.fields(iCorrect + 1)%>。< BR>
<%
结束如果
下一页
rst.MoveFirst
虽然不是rst.EOF
iTotal = iTotal + 1
rst.MoveNext
Wend
%>
< br>
< br>
< hr>
< br>
< h4>测验统计数据:< / h4>
< br>
问题数量:& nbsp;& nbsp;& nbsp;<%= iTotal%>
< br>
<%iAnswered = Request.Form.Count%>
< br>
问题数量<回答:& nbsp;& nbsp;& nbsp;<%= iAnswered%>& nbsp;& nb sp;或& nbsp;& nbsp;<%= Forma * tPercent(iAnswered / iTotal,0)%>
< br>
<%iNotAnswered = iTotal-iAnswered%>
问题数量不是
已回答:& nbsp;& nbsp;& nbsp;<%= iNotAnswered%>& nbsp; & nbsp;或& nbsp;& nbsp;<%= Fo * rmatPercent(iNotAnswe red / iTotal,0)%>
< br>
< P>< b>您的回答正确<%= iCorrectCount%<%= iTotal%>
问题
和您的得分为:< / b< B><%= FormatPercent(iCorrectCount /
iTotal,0)%>
< br>
< / font>
< / BODY>
< / HTML>
<%End Sub%>
========================================== ======== ============
To all asp/db pros:
The quiz code below works. But there is a problem when too many
questions are answered (radio buttons clicked). I am not an asp pro.
So, is there a pro out there or an amateur guru who will be so kind as
to volunteer some time to figure out where the bug is? This may mean he
will have to go through the tedious steps of creating an .mdb with a
few records...unless the bug is obvious...
On a page with server-code generated radio buttons (quiz format from 1
to 5 answers max), there is a Submit button. After this button is
clicked, a page shows the answers and other stats. The problem is that
I keep on getting the same error frequently only if more than a certain
number of questions are answered, depending on which questions are
answered, starting from the bottom up or from the top down etc... If
less than, say, half a dozen questions are answered, there is no error.
Go figure...
The line giving the error is: Do While rst("iQuestID") <CInt(x)
This line is in the Sub Quizscore(), in the For Each loop.
Error:
============================================
Error Type:
(0x80020009)
Exception occurred.
/AllQuizzes/xlGenGeneral.asp, line 76
Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322)
Page:
POST 60 bytes to /AllQuizzes/xlGenGeneral.asp
POST Data:
1=2&2=3&3=4&4=3&5=3&6=3&7=4&8=3&9=3&10=2&11=3&12=3 &13=4&14=2
=============================================
<%
Dim conntemp
Dim rst
set oCon=Server.CreateObject("ADODB.Connection")
ocon.Provider="Microsoft.Jet.OLEDB.4.0"
oCon.Open server.mappath("/_private/General.mdb")
Set rst=Server.CreateObject("ADODB.Recordset")
rst.Open "SELECT iQuestID, mQuest, mAns1, mAns2, mAns3, mAns4,
mAns5, iCorrectAns FROM tblGeneral", oCon
If Request.Form.Count = 0 Then
Call Quizpresent
Else
Call Quizscore
End If
oCon.close
set oCon = nothing
%>
<% Sub Quizpresent() %>
<% session("referer") = Request.ServerVariables("HTTP_REFERER") %>
<FORM METHOD="POST" ACTION="xlGenGeneral.asp">
<OL>
<%Do While Not rst.EOF%>
<%=rst("iQuestID")%> <%=rst("mQuest")%> <BR>
<%
Dim i
Dim strChoice
For i = 1 to 5
strChoice = rst.fields(i+1).value
If strChoice <"" Then
%>
<INPUT TYPE="RADIO" NAME="<%=rst("iQuestID")%>" VALUE="<%=i%>">
<%=strChoice%>
<BR>
<%
End If
Next
%>
<BR>
<%
rst.MoveNext
Loop
rst.MoveFirst
%>
<br>
<br>
</OL>
<P><INPUT TYPE="SUBMIT" VALUE="Get Score">
<INPUT TYPE="RESET" VALUE="Clear All Answers">
</FORM>
<% End Sub %>
<%
Sub Quizscore()
Dim x
Dim iTotal
Dim iAnswered
Dim iNotAnswered
Dim iCorrect
Dim iCorrectCount
Dim iChosen
iTotal = 0
icorrectCount = 0
%>
<HTML>
<BODY BGCOLOR="#ffffff">
<font size="2" face="Arial">
<h4>Quiz results:</h4>
<%
For Each x in Request.Form
Do While rst("iQuestID") <CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst("iCorrectAns"))
iChosen = CInt(Request.Form(x))
%>
<P>
The question<%=rst("iQuestID")%>was:<%=rst("mQuest") %><BR>
Your answer was:<%= rst.fields(iChosen+1).value %>.<BR>
<%
If iChosen = iCorrect Then
iCorrectCount = iCorrectCount + 1
%>
<font color="#008000">Correct answer</font>.<BR>
<%
Else
%>
<font color="#FF00000">Incorrect answer</font>. The correct answer
is:<%=rst.fields(iCorrect+1)%>.<BR>
<%
End If
Next
rst.MoveFirst
While Not rst.EOF
iTotal = iTotal + 1
rst.MoveNext
Wend
%>
<br>
<br>
<hr>
<br>
<h4>Quiz statistics:</h4>
<br>
Number of questions: <%=iTotal%>
<br>
<%iAnswered=Request.Form.Count%>
<br>
Number of questions
answered: <%=iAnswered%> &nb sp;or <%=Forma*tPercent(iAnswered/iTotal,0)%>
<br>
<%iNotAnswered=iTotal-iAnswered%>
Number of questions not
answered: <%=iNotAnswered%> or <%=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 %>
================================================== ============
推荐答案
< ma ************* @ hotmail.comwrote in message
news:11 ************** ********@e3g2000cwe.googlegro ups.com ...
致所有asp / db专业人士:
以下测验代码有效。但是,当答案太多(单击单选按钮)时,会出现问题。我不是一个asp专业人士。
那么,是否有专业人士或业余专家会如此善良,以便志愿者花一些时间来弄清楚bug是?这可能意味着他将需要经历繁琐的步骤来创建一个带有
几条记录的.mdb ...除非这个bug很明显......
在一个包含服务器代码生成单选按钮的页面上(测验格式从1
到最多5个答案),有一个提交按钮。点击此按钮后,页面会显示答案和其他统计信息。问题是
只有当问题的答案超过一定数量时才会经常出现同样的错误,具体取决于哪些问题
回答,从下往上或从上到下等等...如果
小于,比如,回答了六个问题,则没有错误。
去图...
给出错误的行是:执行rst(" iQuestID")< CInt(x)
这一行在For Quizscore()中,在For Each循环中。
错误:
======== ====================================
错误类型:
(0x80020009)
发生异常。
/AllQuizzes/xlGenGeneral.asp,第76行
Mozilla / 4.0(兼容; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322)
页:
POST 60个字节到/AllQuizzes/xlGenGeneral.asp
POST数据:
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")
设置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
致电Quizscore
结束如果
oCon.close
set oCon = nothing
%>
<%Sub Quizpresent()%>
<%session(" referer")= Request.ServerVariables(" HTTP_REFERER")% >
< FORM METHOD =" POST&qu OT; ACTION =" xlGenGeneral.asp">
< OL>
<%Do not whilerst.EOF%>
<%= RST(" iQuestID")%>&安培; NBSP;&安培; NBSP;<%= RST(" mQuest")%> < BR>
<%
Dim i
Dim strChoice
i = 1到5
strChoice = rst.fields(i + 1).value
如果strChoice<""然后
%>
< INPUT TYPE =" RADIO" NAME ="<%= RST(" iQuestID")%>" VALUE ="<%= i%>">
<%= strChoice%>
< BR>
<%
结束如果
下一页
%>
< BR>
<%
rst.MoveNext
Loop
rst.MoveFirst
%>
< br>
< br>
< / OL>
< P>< ; INPUT TYPE =" SUBMIT" VALUE =获得分数>
< INPUT TYPE =" RESET" VALUE =" Clear All Answers"
< / FORM>
<%End Sub%>
<%
Sub Quizscore()
Dim x
Dim iTotal
Dim iAnswers
Dim iNotAtwered
Dim iCorrect
Dim iCorrectCount
Dim iChosen
iTotal = 0
icorrectCount = 0
%>
< HTML>
< BODY BGCOLOR =" #fffff">
< font size =" 2" face =" Arial">
< h4>测验结果:< / h4>
<%
每个x在Request.Form
做rst(" iQuestID")< CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst(" iCorrectAns"))
iChosen = CInt(Request.Form(x))
%>
< P>
问题<%= rst(" iQuestID")%>为:<%= rst(" mQuest")%>< BR>
您的回答是:<%= rst.fields(iChosen + 1).value%>。< BR>
<%
如果iChosen = iCorrect那么
iCorrectCount = iCorrectCount + 1
%>
< font color ="# 008000">正确答案< / font>。< BR>
<%
否则
%>
< font color ="#FF00000">错误答案< / font>。正确的答案
是:<%= rst.fields(iCorrect + 1)%>。< BR>
<%
结束如果
下一页
rst.MoveFirst
虽然不是rst.EOF
iTotal = iTotal + 1
rst.MoveNext
Wend
%>
< br>
< br>
< hr>
< br>
< h4>测验统计数据:< / h4>
< br>
问题数量:& nbsp;& nbsp;& nbsp;<%= iTotal%>
< br>
<%iAnswered = Request.Form.Count%>
< br>
问题数量<回答:& nbsp;& nbsp;& nbsp;<%= iAnswered%>& nbsp;& nb sp;或& nbsp;& nbsp;<%= Forma * tPercent(iAnswered / iTotal,0)%>
< br>
<%iNotAnswered = iTotal-iAnswered%>
问题数量不是
已回答:& nbsp;& nbsp;& nbsp;<%= iNotAnswered%>& nbsp; & nbsp;或& nbsp;& nbsp;<%= Fo * rmatPercent(iNotAnswe red / iTotal,0)%>
< br>
< P>< b>您的回答正确<%= iCorrectCount%<%= iTotal%>
问题
和您的得分为:< / b< B><%= FormatPercent(iCorrectCount /
iTotal,0)%>
< br>
< / font>
< / BODY>
< / HTML>
<%End Sub%>
========================================== ======== ============
至少一个x不是数字。 Request.Form(Submit)将始终等于
Get Score。在For ...每个循环中添加一个条件,以便从
转换为int中省略。
For Request.Form中的每个x
如果x<"提交"然后
Do While rst(" iQuestID")< CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst(" iCorrectAns"))
iChosen = CInt(Request.Form(x))
....
....
结束如果
下一页
-
Mike Brind
<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")%> <%=rst("mQuest")%> <BR>
<%
Dim i
Dim strChoice
For i = 1 to 5
strChoice = rst.fields(i+1).value
If strChoice <"" Then
%>
<INPUT TYPE="RADIO" NAME="<%=rst("iQuestID")%>" VALUE="<%=i%>">
<%=strChoice%>
<BR>
<%
End If
Next
%>
<BR>
<%
rst.MoveNext
Loop
rst.MoveFirst
%>
<br>
<br>
</OL>
<P><INPUT TYPE="SUBMIT" VALUE="Get Score">
<INPUT TYPE="RESET" VALUE="Clear All Answers">
</FORM>
<% End Sub %>
<%
Sub Quizscore()
Dim x
Dim iTotal
Dim iAnswered
Dim iNotAnswered
Dim iCorrect
Dim iCorrectCount
Dim iChosen
iTotal = 0
icorrectCount = 0
%>
<HTML>
<BODY BGCOLOR="#ffffff">
<font size="2" face="Arial">
<h4>Quiz results:</h4>
<%
For Each x in Request.Form
Do While rst("iQuestID") <CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst("iCorrectAns"))
iChosen = CInt(Request.Form(x))
%>
<P>
The question<%=rst("iQuestID")%>was:<%=rst("mQuest") %><BR>
Your answer was:<%= rst.fields(iChosen+1).value %>.<BR>
<%
If iChosen = iCorrect Then
iCorrectCount = iCorrectCount + 1
%>
<font color="#008000">Correct answer</font>.<BR>
<%
Else
%>
<font color="#FF00000">Incorrect answer</font>. The correct answer
is:<%=rst.fields(iCorrect+1)%>.<BR>
<%
End If
Next
rst.MoveFirst
While Not rst.EOF
iTotal = iTotal + 1
rst.MoveNext
Wend
%>
<br>
<br>
<hr>
<br>
<h4>Quiz statistics:</h4>
<br>
Number of questions: <%=iTotal%>
<br>
<%iAnswered=Request.Form.Count%>
<br>
Number of questions
answered: <%=iAnswered%> &nb sp;or <%=Forma*tPercent(iAnswered/iTotal,0)%>
<br>
<%iNotAnswered=iTotal-iAnswered%>
Number of questions not
answered: <%=iNotAnswered%> or <%=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 Brind写道:
Mike Brind wrote:
< ma **** *********@hotmail.com写信息
新闻:11 ********************** @ e3g2000cwe .googlegro ups.com ...
致所有asp / db专业人士:
以下测验代码有效。但是,当答案太多(单击单选按钮)时,会出现问题。我不是一个asp专业人士。
那么,是否有专业人士或业余专家会如此善良,以便志愿者花一些时间来弄清楚bug是?这可能意味着他将需要经历繁琐的步骤来创建一个带有
几条记录的.mdb ...除非这个bug很明显......
在一个包含服务器代码生成单选按钮的页面上(测验格式从1
到最多5个答案),有一个提交按钮。点击此按钮后,页面会显示答案和其他统计信息。问题是
只有当问题的答案超过一定数量时才会经常出现同样的错误,具体取决于哪些问题
回答,从下往上或从上到下等等...如果
小于,比如,回答了六个问题,则没有错误。
去图...
给出错误的行是:执行rst(" iQuestID")< CInt(x)
这一行在For Quizscore()中,在For Each循环中。
错误:
======== ====================================
错误类型:
(0x80020009)
发生异常。
/AllQuizzes/xlGenGeneral.asp,第76行
Mozilla / 4.0(兼容; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322)
页:
POST 60个字节到/AllQuizzes/xlGenGeneral.asp
POST数据:
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")
设置rst = Server.CreateObject(" ADODB.Recordset")
rst.Open" SELECT iQuestID,mQuest,mAns1,mAns2,mAns3,mAns4,
mAns5,iCorrectAns FROM tblGeneral",oCon
如果Request.Form.Count = 0那么
致电测验
Else
致电Quizscore
结束如果
oCon.close
set oCon =什么都没有
%>
<%Sub Quizpresent()%>
<%session(" referer")= Request.ServerV ariables(HTTP_REFERER)%>
< FORM METHOD =" POST" ACTION =" xlGenGeneral.asp">
< OL>
<%Do not whilerst.EOF%>
<%= RST(" iQuestID")%>&安培; NBSP;&安培; NBSP;<%= RST(" mQuest")%> < BR>
<%
Dim i
Dim strChoice
i = 1到5
strChoice = rst.fields(i + 1).value
如果strChoice<""然后
%>
< INPUT TYPE =" RADIO" NAME ="<%= RST(" iQuestID")%>" VALUE ="<%= i%>">
<%= strChoice%>
< BR>
<%
结束如果
下一页
%>
< BR>
<%
rst.MoveNext
Loop
rst.MoveFirst
%>
< br>
< br>
< / OL>
< P>< ; INPUT TYPE =" SUBMIT" VALUE =获得分数>
< INPUT TYPE =" RESET" VALUE =" Clear All Answers"
< / FORM>
<%End Sub%>
<%
Sub Quizscore()
Dim x
Dim iTotal
Dim iAnswers
昏暗iNotAnswered
昏暗iCorrect
昏暗iCorrectCount
昏暗iChosen
iTotal = 0
icorrectCount = 0
%>
< HTML>
< BODY BGCOLOR =" #fffff"> ;
< font size =" 2" face =" Arial">
< h4>测验结果:< / h4>
<%
每个x在Request.Form
做rst(" iQuestID")< CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst(" iCorrectAns"))
iChosen = CInt(Request.Form(x))
%>
< P>
问题<%= rst(" iQuestID")%>为:<%= rst(" mQuest")%>< BR>
您的回答是:<%= rst.fields(iChosen + 1).value%>。< BR>
<%
如果iChosen = iCorrect那么
iCorrectCount = iCorrectCount + 1
%>
< font color ="# 008000">正确答案< / font>。< BR>
<%
否则
%>
< font color ="#FF00000">错误答案< / font>。正确的答案
是:<%= rst.fields(iCorrect + 1)%>。< BR>
<%
结束如果
下一页
rst.MoveFirst
虽然不是rst.EOF
iTotal = iTotal + 1
rst.MoveNext
Wend
%>
< br>
< br>
< hr>
< br>
< h4>测验统计数据:< / h4>
< br>
问题数量:& nbsp;& nbsp;& nbsp;<%= iTotal%>
< br>
<%iAnswered = Request.Form.Count%>
< br>
问题数量
已回答:& nbsp;& nbsp;& nbsp;<%= iAnswered%>& nbsp;& nb sp;或& nbsp;& nbsp; <%= Forma * tPercent(iAnswered / iTotal,0)%>
< br>
<%iNotAnswered = iTotal-iAnswered% >
问题数量不是
已回答:& nbsp;& nbsp;& nbsp;<%= iN otAnswered%GT;&安培; NBSP; & nbsp;或& nbsp;& nbsp;<%= Fo * rmatPercent(iNotAnswe red / iTotal,0)%>
< br>
< P>< b>您的回答正确<%= iCorrectCount%<%= iTotal%>
问题
和您的得分为:< / b< B><%= FormatPercent(iCorrectCount /
iTotal,0)%>
< br>
< / font>
< / BODY>
< / HTML>
<%End Sub%>
====================================== ============ ============
至少一个x不是数字。 Request.Form(Submit)将始终等于
Get Score。在For ...每个循环中添加一个条件,以便从
转换为int中省略。
For Request.Form中的每个x
如果x<"提交"然后
Do While rst(" iQuestID")< CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst(" iCorrectAns"))
iChosen = CInt(Request.Form(x))
...
...
结束如果
下一页
-
Mike Brind
<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")%> <%=rst("mQuest")%> <BR>
<%
Dim i
Dim strChoice
For i = 1 to 5
strChoice = rst.fields(i+1).value
If strChoice <"" Then
%>
<INPUT TYPE="RADIO" NAME="<%=rst("iQuestID")%>" VALUE="<%=i%>">
<%=strChoice%>
<BR>
<%
End If
Next
%>
<BR>
<%
rst.MoveNext
Loop
rst.MoveFirst
%>
<br>
<br>
</OL>
<P><INPUT TYPE="SUBMIT" VALUE="Get Score">
<INPUT TYPE="RESET" VALUE="Clear All Answers">
</FORM>
<% End Sub %>
<%
Sub Quizscore()
Dim x
Dim iTotal
Dim iAnswered
Dim iNotAnswered
Dim iCorrect
Dim iCorrectCount
Dim iChosen
iTotal = 0
icorrectCount = 0
%>
<HTML>
<BODY BGCOLOR="#ffffff">
<font size="2" face="Arial">
<h4>Quiz results:</h4>
<%
For Each x in Request.Form
Do While rst("iQuestID") <CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst("iCorrectAns"))
iChosen = CInt(Request.Form(x))
%>
<P>
The question<%=rst("iQuestID")%>was:<%=rst("mQuest") %><BR>
Your answer was:<%= rst.fields(iChosen+1).value %>.<BR>
<%
If iChosen = iCorrect Then
iCorrectCount = iCorrectCount + 1
%>
<font color="#008000">Correct answer</font>.<BR>
<%
Else
%>
<font color="#FF00000">Incorrect answer</font>. The correct answer
is:<%=rst.fields(iCorrect+1)%>.<BR>
<%
End If
Next
rst.MoveFirst
While Not rst.EOF
iTotal = iTotal + 1
rst.MoveNext
Wend
%>
<br>
<br>
<hr>
<br>
<h4>Quiz statistics:</h4>
<br>
Number of questions: <%=iTotal%>
<br>
<%iAnswered=Request.Form.Count%>
<br>
Number of questions
answered: <%=iAnswered%> &nb sp;or <%=Forma*tPercent(iAnswered/iTotal,0)%>
<br>
<%iNotAnswered=iTotal-iAnswered%>
Number of questions not
answered: <%=iNotAnswered%> or <%=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
==================================== ============== =============================
迈克,
谢谢。
不。没运气。我仍然收到错误:
错误类型:
(0x80020009)
发生异常。
>
我想到了你的建议,如果我很久以前尝试过
,我也不会感到惊讶。我之前在这里和那里尝试了很多比特......我不知道究竟究竟是什么。我记得所有都没有用。
我不确定底部按钮是否重要,因为代码
按预期工作,不会产生错误当几个问题是
回答。怎么会?当按钮在循环中获得
时,它不应该在最后打破吗?另外,我不确定首先处理哪个x'。
所有单选按钮然后是最后两个按钮?我这么认为。此外,
没有一个按钮有NAME参数,所以我认为它们在循环中跳过了
...
无论如何,即使在检测到If x<" SUBMIT"然后或如果x<>
" SUBMIT" AND x<" RESET"然后,我仍然得到错误。
我尝试给两个按钮一个带名字的NAME参数,而且
也没有什么区别。
================================================== =============================
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.
< ma ************* @ hotmail.comwrote in message
news:11 * *********************@k70g2000cwa.googlegr oups.com ...
Mike Brind写道:
<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 ...
致所有asp / db专业人士:
>
以下测验代码有效。但是,当答案太多(单击单选按钮)时,会出现问题。我不是一个asp专业人士。
那么,是否有专业人士或业余专家会如此善良,以便志愿者花一些时间来弄清楚bug是?这可能意味着他将需要经历繁琐的步骤来创建一个带有
几条记录的.mdb ...除非这个bug很明显......
在一个包含服务器代码生成单选按钮的页面上(测验格式从1
到最多5个答案),有一个提交按钮。点击此按钮后,页面会显示答案和其他统计信息。问题是
只有当问题的答案超过一定数量时才会经常出现同样的错误,具体取决于哪些问题
回答,从下往上或从上到下等等...如果
小于,比如,回答了六个问题,则没有错误。
去图...
给出错误的行是:执行rst(" iQuestID")< CInt(x)
这一行在For Quizscore()中,在For Each循环中。
错误:
======== ====================================
错误类型:
(0x80020009)
发生异常。
/AllQuizzes/xlGenGeneral.asp,第76行
Mozilla / 4.0(兼容; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322)
页:
POST 60个字节到/AllQuizzes/xlGenGeneral.asp
POST数据:
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")
设置rst = Server.CreateObject(" ADODB.Recordset")
rst.Open" SELECT iQuestID,mQuest,mAns1,mAns2,mAns3,mAns4,
mAns5,iCorrectAns FROM tblGeneral",oCon
如果Request.Form.Count = 0那么
致电测验
Else
致电Quizscore
结束如果
oCon.close
set oCon =什么都没有
%>
<%Sub Quizpresent()%>
<%session(" referer")= Request.ServerV ariables(HTTP_REFERER)%>
< FORM METHOD =" POST" ACTION =" xlGenGeneral.asp">
< OL>
<%Do not whilerst.EOF%>
<%= RST(" iQuestID")%>&安培; NBSP;&安培; NBSP;<%= RST(" mQuest")%> < BR>
<%
Dim i
Dim strChoice
i = 1到5
strChoice = rst.fields(i + 1).value
如果strChoice<""然后
%>
< INPUT TYPE =" RADIO" NAME ="<%= RST(" iQuestID")%>" VALUE ="<%= i%>">
<%= strChoice%>
< BR>
<%
结束如果
下一页
%>
< BR>
<%
rst.MoveNext
Loop
rst.MoveFirst
%>
< br>
< br>
< / OL>
< P>< ; INPUT TYPE =" SUBMIT" VALUE =获得分数>
< INPUT TYPE =" RESET" VALUE =" Clear All Answers"
< / FORM>
<%End Sub%>
<%
Sub Quizscore()
Dim x
Dim iTotal
Dim iAnswers
昏暗iNotAnswered
昏暗iCorrect
昏暗iCorrectCount
昏暗iChosen
iTotal = 0
icorrectCount = 0
%>
< HTML>
< BODY BGCOLOR =" #fffff"> ;
< font size =" 2" face =" Arial">
< h4>测验结果:< / h4>
<%
每个x在Request.Form
做rst(" iQuestID")< CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst(" iCorrectAns"))
iChosen = CInt(Request.Form(x))
%>
< P>
问题<%= rst(" iQuestID")%>为:<%= rst(" mQuest")%>< BR>
您的回答是:<%= rst.fields(iChosen + 1).value%>。< BR>
<%
如果iChosen = iCorrect那么
iCorrectCount = iCorrectCount + 1
%>
< font color ="# 008000">正确答案< / font>。< BR>
<%
否则
%>
< font color ="#FF00000">错误答案< / font>。正确的答案
是:<%= rst.fields(iCorrect + 1)%>。< BR>
<%
结束如果
下一页
rst.MoveFirst
虽然不是rst.EOF
iTotal = iTotal + 1
rst.MoveNext
Wend
%>
< br>
< br>
< hr>
< br>
< h4>测验统计数据:< / h4>
< br>
问题数量:& nbsp;& nbsp;& nbsp;<%= iTotal%>
< br>
<%iAnswered = Request.Form.Count%>
< br>
问题数量
已回答:& nbsp;& nbsp;& nbsp;<%= iAnswered%>& nbsp;& nb sp;或& nbsp;& nbsp; <%= Forma * tPercent(iAnswered / iTotal,0)%>
< br>
<%iNotAnswered = iTotal-iAnswered% >
问题数量不是
已回答:& nbsp;& nbsp;& nbsp;<%= iN otAnswered%GT;&安培; NBSP; & nbsp;或& nbsp;& nbsp;<%= Fo * rmatPercent(iNotAnswe red / iTotal,0)%>
< br>
< P>< b>您的回答正确<%= iCorrectCount%<%= iTotal%>
问题
和您的得分为:< / b< B><%= FormatPercent(iCorrectCount /
iTotal,0)%>
< br>
< / font>
< / BODY>
< / HTML>
<%End Sub%>
====================================== ============ ============
至少一个x不是数字。 Request.Form(Submit)将始终等于
Get Score。在For ...每个循环中添加一个条件,以便从
转换为int中省略。
For Request.Form中的每个x
如果x<"提交" Then
Do While rst("iQuestID") <CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst("iCorrectAns"))
iChosen = CInt(Request.Form(x))
...
...
End If
Next
--
Mike Brind
<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")%> <%=rst("mQuest")%> <BR>
<%
Dim i
Dim strChoice
For i = 1 to 5
strChoice = rst.fields(i+1).value
If strChoice <"" Then
%>
<INPUT TYPE="RADIO" NAME="<%=rst("iQuestID")%>" VALUE="<%=i%>">
<%=strChoice%>
<BR>
<%
End If
Next
%>
<BR>
<%
rst.MoveNext
Loop
rst.MoveFirst
%>
<br>
<br>
</OL>
<P><INPUT TYPE="SUBMIT" VALUE="Get Score">
<INPUT TYPE="RESET" VALUE="Clear All Answers">
</FORM>
<% End Sub %>
<%
Sub Quizscore()
Dim x
Dim iTotal
Dim iAnswered
Dim iNotAnswered
Dim iCorrect
Dim iCorrectCount
Dim iChosen
iTotal = 0
icorrectCount = 0
%>
<HTML>
<BODY BGCOLOR="#ffffff">
<font size="2" face="Arial">
<h4>Quiz results:</h4>
<%
For Each x in Request.Form
Do While rst("iQuestID") <CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst("iCorrectAns"))
iChosen = CInt(Request.Form(x))
%>
<P>
The question<%=rst("iQuestID")%>was:<%=rst("mQuest") %><BR>
Your answer was:<%= rst.fields(iChosen+1).value %>.<BR>
<%
If iChosen = iCorrect Then
iCorrectCount = iCorrectCount + 1
%>
<font color="#008000">Correct answer</font>.<BR>
<%
Else
%>
<font color="#FF00000">Incorrect answer</font>. The correct answer
is:<%=rst.fields(iCorrect+1)%>.<BR>
<%
End If
Next
rst.MoveFirst
While Not rst.EOF
iTotal = iTotal + 1
rst.MoveNext
Wend
%>
<br>
<br>
<hr>
<br>
<h4>Quiz statistics:</h4>
<br>
Number of questions: <%=iTotal%>
<br>
<%iAnswered=Request.Form.Count%>
<br>
Number of questions
answered: <%=iAnswered%> &nb sp;or <%=Forma*tPercent(iAnswered/iTotal,0)%>
<br>
<%iNotAnswered=iTotal-iAnswered%>
Number of questions not
answered: <%=iNotAnswered%> or <%=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
================================================== =============================
\t
================================================== =============================
\t
\t\t\t\t>Mike,
Thanks.
Nope.没运气。 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.怎么会? 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...
>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...
\t
\t\t\t\t>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.
>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
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
这篇关于Quizz脚本性能错误 - 问题太多了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!