Request.Form and radio buttons

What is causing the error in the block of code posted?

Page 1 of 1

0 Replies - 8270 Views - Last Post: 28 September 2006 - 02:28 PM Rate Topic: -----

#1 VBA_VB_BLOKE  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-September 06

Request.Form and radio buttons

Posted 28 September 2006 - 02:28 PM

Hello,

I posted the following code in the newsgroup:
microsoft.public.inetserver.asp.db
The title of the post is:
Request.Form and radio buttons

Can someone answer the question there or here? I have attached the .mdb
I have spent too much time on trying to fix the error. I have to leave it to ASP pros.

Here is the same code:
====================================================
Hi,

On a page with server-code generated radio buttons (quiz format from 1
to 5 answers max), there is a Submit button. After this button is
clicked, a page shows the answers and other stats. The problem is that
I keep on getting the same error frequently only if more than a certain
number of questions are answered, depending on which questions are
answered. If less than, say, half a dozen questions are answered, there
is no error. Am I posting a string too long and beyond some limit? I
doubt it.
The line giving the error is: Do While rst("iQuestID") <> CInt(x)
This line is in the Sub Quizscore(), in the For Each loop.
Any ideas?


Error example:
============================================
Error Type:
(0x80020009)
Exception occurred.
/AllQuizzes/xlGenGeneral.asp, line 76
Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322)
Page:
POST 60 bytes to /AllQuizzes/xlGenGeneral.asp
POST Data:
1=2&2=3&3=4&4=3&5=3&6=3&7=4&8=3&9=3&10=2&11=3&12=3&13=4&14=2
=============================================
<%
Dim conntemp
Dim rst


set oCon=Server.CreateObject("ADODB.Connection")
ocon.Provider="Microsoft.Jet.OLEDB.4.0"
oCon.Open server.mappath("/_private/General.mdb")
Set rst=Server.CreateObject("ADODB.Recordset")
rst.Open "SELECT iQuestID, mQuest, mAns1, mAns2, mAns3, mAns4,
mAns5, iCorrectAns FROM tblGeneral", oCon


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


oCon.close
set oCon = nothing


%>


<% Sub Quizpresent() %>


<% session("referer") = Request.ServerVariables("HTTP_REFERER") %>
<FORM METHOD="POST" ACTION="xlGenGeneral.asp">
<OL>
<%Do While Not rst.EOF%>
<%=rst("iQuestID")%>  <%=rst("mQuest")%><BR>
<%
Dim i
Dim strChoice
For i = 1 to 5
strChoice = rst.fields(i+1).value
If strChoice <> "" Then
%>
<INPUT TYPE="RADIO" NAME="<%=rst("iQuestID")%>" VALUE="<%=i%>">
<%=strChoice%>
<BR>
<%
End If
Next
%>
<BR>
<%
rst.MoveNext
Loop
rst.MoveFirst
%>
<br>
<br>
</OL>
<P><INPUT TYPE="SUBMIT" VALUE="Get Score">
<INPUT TYPE="RESET" VALUE="Clear All Answers">
</FORM>
<% End Sub %>


<%
Sub Quizscore()
Dim x
Dim iTotal
Dim iAnswered
Dim iNotAnswered
Dim iCorrect
Dim iCorrectCount
Dim iChosen
iTotal = 0
icorrectCount = 0
%>
<HTML>
<BODY BGCOLOR="#ffffff">
<font size="2" face="Arial">
<h4>Quiz results:</h4>
<%
For Each x in Request.Form
Do While rst("iQuestID") <> CInt(x)
rst.MoveNext
Loop
iCorrect = CInt(rst("iCorrectAns"))
iChosen = CInt(Request.Form(x))
%>
<P>
The question<%=rst("iQuestID")%>was:<%=rst("mQuest") %><BR>
Your answer was:<%= rst.fields(iChosen+1).value %>.<BR>
<%
If iChosen = iCorrect Then
iCorrectCount = iCorrectCount + 1
%>
<font color="#008000">Correct answer</font>.<BR>
<%
Else
%>
<font color="#FF00000">Incorrect answer</font>. The correct answer
is:<%=rst.fields(iCorrect+1)%>.<BR>
<%
End If
Next


rst.MoveFirst
While Not rst.EOF
iTotal = iTotal + 1
rst.MoveNext
Wend
%>
<br>
<br>
<hr>
<br>
<h4>Quiz statistics:</h4>
<br>
Number of questions:   <%=iTotal%>
<br>
<%iAnswered=Request.Form.Count%>
<br>
Number of questions
answered:   <%=iAnswered%>  or  <%=Forma­tPercent(iAnswered/iTotal,0)%>
<br>
<%iNotAnswered=iTotal-iAnswered%>
Number of questions not
answered:   <%=iNotAnswered%>  or  <%=Fo­rmatPercent(iNotAnswered/iTotal,0)%>
<br>
<P><b>You answered correctly <%=iCorrectCount%> out of <%=iTotal%>
questions
and your score is : </b> <B><%=FormatPercent(iCorrectCount /
iTotal,0)%>
<br>
</font>
</BODY>
</HTML>


<% End Sub %>

Is This A Good Question/Topic? 0
  • +

Page 1 of 1