ChristianX
Programmer
Good morning all,
I have devleoped a quiz system that i will be using on my new site. I have the quiz script wrote, however, there are a number of quizzes that a user may take. These are stored in a MS Access database, each with a unique TestID. The quiz script at the moment works grand, however i have hardcoded the TestID in, which though it works it not efficient. What i want is for the user to select a book they have read froma drop down list box (which popoluates from the database Book Tabel), and upon submittance of this another list box appears which popoluates with tests associated to that book (via foreign key BookID in the Test Table).
Essentailly what i need to do is when the user clicks on the test they want to do(from the 2nd list box) the quiz page will load with the appropriate test.
Here is what i have created so far, but have run up against a brick wall! Can anyone be the saviour?! Thanks guys for your time.
bookdropdown.asp (which will provide drop boxes)
<!--#include file="Clssfd.asp"-->
<%
Dim rsBook, rsTest
Dim iRequestedID
' Some basic checking and cleaning of the input
iRequestedID = Trim(Request.QueryString("BookID")
iRequestedID = Replace(iRequestedID, "'", "''"
If IsNumeric(iRequestedID) Then
iRequestedID = CInt(iRequestedID)
Else
iRequestedID = 0
End If
' The form links back to this same file passing back the id
%>
<p>To add a question: Select the book that the question relates to</p>
<form action="bookdropdown.asp" method="GET">
<%
' Build our query for select box 1
strSQL= "SELECT * FROM Book ORDER BY Title"
Set rsBook = Server.CreateObject("ADODB.Recordset"
rsBook.Open strSQL, objConn
' build our first drop down with lists of books
If Not rsBook.EOF Then
rsBook.MoveFirst
%>
<SELECT NAME="BookID"><option>Select Book</option>
<%
' Loop through books
Do While Not rsBook.EOF
Response.Write "<option value="""
Response.Write rsBook.Fields("BookID"
Response.Write """"
If rsBook.Fields("BookID" = CInt(iRequestedID) Then
Response.Write "selected=""true"""
End If
Response.Write ">"
Response.Write Trim(rsBook.Fields("Title")
Response.Write "</option>" & vbCrLf
' Move to next record
rsBook.MoveNext
Loop
%>
</select>
<%
End If
rsBook.Close
Set rsBook = Nothing
' If a request for a specific id comes in, then build second select box
If iRequestedID <> 0 Then
strSQL = "SELECT * FROM Test WHERE BookId = " _
& iRequestedID & " ORDER BY TestName"
Set rsTest = Server.CreateObject("ADODB.Recordset"
rsTest.Open strSQL, objConn, adOpenForwardOnly, adLockOptimistic, adCmdText
' Build our drop down box of the tests
If Not rsTest.EOF Then
rsTest.MoveFirst
%>
<select name="TestID"><option>Select the test to add the question to</option>
<% ' Loop through tests
Do While Not rsTest.EOF
Response.Write "<option>"
Response.Write Trim(rsTest.Fields("TestName")
Response.Write "</option>" & vbCrLf
' Move to next record
rsTest.MoveNext
Loop
%>
</select>
<%
End If
' Close ADO objects we're finished with and free DB variables
rsTest.Close
Set rsTest = Nothing
End If
%>
<input type="submit" value="Submit" />
</form>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Then here is the quiz.asp page (Note where i hard coded the testID 'Const TestID = 4'
<!--#include file="Clssfd.asp"-->
<%
' Takes a integer parameter and converts it to the appropriate letter
Function GetLetterFromAnswerNumber(iInput)
Dim strTemp
Select Case iInput
Case 0
strTemp = "A"
Case 1
strTemp = "B"
Case 2
strTemp = "C"
Case 3
strTemp = "D"
Case 4
strTemp = "E"
Case 5
strTemp = "F"
Case 6
strTemp = "G"
Case 7
strTemp = "H"
Case 8
strTemp = "I"
Case 9
strTemp = "J"
End Select
GetLetterFromAnswerNumber = strTemp
End Function
' Create a fuction
Function GetAnswerFromAnswerString(iQuestionID, strAnswers)
Dim strTemp
Dim iOffset
' I use InStrRev since I want to retrieve the last entered value
' in case they went back and changed their mind.
' Find the location of the question number we want to use
iOffset = InStrRev(strAnswers, "|" & iQuestionID & "|", -1, 1)
' Get our answer by using the offset we just found and then moving
' right the length of the question indicator to arrive at the
' appropriate letter
strTemp = Mid(strAnswers, iOffset + Len("|" & iQuestionID & "|", 1)
' There's no way it should be anything else, but to be sure we
' convert it to a string and make sure it's uppercase
GetAnswerFromAnswerString = UCase(CStr(strTemp))
End Function
%>
<%
' Lets you run multiple Test from one DB by separating by TestID!
Const TestID = 4
' Now to all our other variables!
Dim cnnTest, rsTest 'DB objects if we use the DB for the info
Dim I 'our standard (improperly named) looping variable
Dim iNumberOfQuestion 'the number of questions in the test
Dim iQuestionID 'the question we're currently on
Dim strQuestionText 'text of the question to be asked
Dim aAnswers 'array of choices for the question to be asked
'if we hard code, then I also use it for the
'correct answers when I go to grade the quiz
Dim strAnswers 'stores the question numbers and response choices
'seperated by |'s
Dim iScore 'so we know how well the user did
Dim bAbort 'added after I had finished to account for closed sessions
Dim strResults 'another late addition for the each question breakdown!
bAbort = False 'set it to false since we only want to abort in certain cases
' If this is the first call to the quiz then init everything
' o/w retrieve values we need. We check by looking for the
' Question ID from the querystring.
If Request.QueryString("qid" = "" Then
' Retrieve and Set the Quiz Info
' Code to use DB!
' Create DB connection and connect to the DB
Set cnnTest = Server.CreateObject("ADODB.Connection"
cnnTest.Open objConn
' Create RS and query DB for quiz info
Set rsTest = Server.CreateObject("ADODB.Recordset"
rsTest.Open "SELECT * FROM Test WHERE TestID=" & TestID & ";", cnnTest
' Set our session vars
Session("TestName" = CStr(rsTest.Fields("TestName".Value)
Session("NumberOfQuestions" = CInt(rsTest.Fields("NumberOfQuestions".Value)
Session("PercentageToPass" = CInt(rsTest.Fields("PercentageToPass".Value)
' Close and dispose of our DB objects
rsTest.Close
Set rsTest = Nothing
cnnTest.Close
Set cnnTest = Nothing
' Set our question indicator to 1 and init our answer string
iQuestionID = 1
Session("AnswerString" = "|"
Else
'Check to be sure we've still got a session!
If Session("AnswerString" = "" Then
Response.Write "I'm sorry, but you've taken too long. You can start over by "
Response.Write "clicking <A HREF=""" & Request.ServerVariables("URL" & """>here</A>."
'to get the script to complete declared and set a Flag
'Response.End
bAbort = True
End If
' Get the number of the question we're processing
iQuestionID = CInt(Request.QueryString("qid")
' Log selected answer to last question
Session("AnswerString" = Session("AnswerString" & iQuestionID & "|" & _
GetLetterFromAnswerNumber(CInt(Request.QueryString("sa")) & "|"
' Increment question identifier
iQuestionID = iQuestionID + 1
End If
' If session has expired then skip all the code.
' Equivalently, only run all the code if it hasn't!
If Not bAbort Then
' Set this to a local variable to avoid accessing the collection each time
' This isn't required, but makes it easier for me to access and
' supposedly speeds it up... I'm not sure how much, but it can't hurt!
iNumberOfQuestions = Session("NumberOfQuestions"
' Check to see it the quiz is over. If so then show results, o/w
' ask the next question
If iQuestionID > iNumberOfQuestions Then
' Process results and show end quiz status report
' Done for the same reason as for iNumberOfQuestions a few lines above
strAnswers = Session("AnswerString"
' Useful for debugging
'Response.Write strAnswers & "
" & vbCrLf & "
" & vbCrLf
' Bug hunting once again... I didn't even come across any real bugs on this trip!
' Could you imagine the ammo I'd take if it was real hunting I was doing!
'For I = 1 to iNumberOfQuestions
' Response.Write GetAnswerFromAnswerString(I, strAnswers) & "
" & vbCrLf
'Next 'I
' Retrieve Correct Answers and compare to the entered ones
' Code to use DB!
' Create DB connection and connect to the DB
Set cnnTest = Server.CreateObject("ADODB.Connection"
cnnTest.Open objConn
' Create RS and query DB for quiz info
Set rsTest = Server.CreateObject("ADODB.Recordset"
' Specify 3, 1 (Static, Read Only)
rsTest.Open "SELECT * FROM Question WHERE TestID=" & TestID & _
" ORDER BY QuestionID;", cnnTest, 3, 1
iScore = 0
I = 1
Do While Not rsTest.EOF
If UCase(CStr(rsTest.Fields("CorrectAnswer".Value)) = _
GetAnswerFromAnswerString(I, strAnswers) Then
iScore = iScore + 1
' This and the Else could be used to output a
' correctness status for each question
' Also useful for bug hunting!
'Response.Write "Right" & "
" & vbCrLf
Else
'Response.Write "Wrong" & "
" & vbCrLf
strResults = strResults & I & ", "
End If
I = I + 1
rsTest.MoveNext
Loop
' Close and dispose of our DB objects
rsTest.Close
Set rsTest = Nothing
cnnTest.Close
Set cnnTest = Nothing
' Convert score to a percentage rounded to the whole number
iScore = Round((iScore / iNumberOfQuestions) * 100)
%>
<FONT SIZE="+2"><B><%= Session("TestName" %></B></FONT>
<%
If iScore >= Session("PercentageToPass" Then
Response.Write "Congratulations! You've passed the quiz with a score of "
Response.Write iScore & "%.
" & vbCrLf
Else
Response.Write "Sorry! You needed to achieve a score of "
Response.Write Session("PercentageToPass" & "% or higher to pass. "
Response.Write "Unfortunately, your score was only " & iScore & "%. "
Response.Write "You can take the test again by clicking <A HREF="""
Response.Write Request.ServerVariables("URL" & """>here</A>.
" & vbCrLf
End If
Response.Write "
" & vbCrLf
If Len(strResults) <> 0 Then
Response.Write "You missed the following questions: " & Left(strResults, Len(strResults) - 2)
Response.Write "
" & vbCrLf
End If
'Response.Write iScore & "%"
' This is also where you could log the results if you wanted to.
' In it's simplest form, you would simply log strAnswers to a file,
' but you could format little "report cards" or log the result to a
' separate data source.
Else
' Retrieve and Set the Question Info
' Code to use DB!
' Create DB connection and connect to the DB
Set cnnTest = Server.CreateObject("ADODB.Connection"
cnnTest.Open objConn
' Create RS and query DB for quiz info
Set rsTest = Server.CreateObject("ADODB.Recordset"
rsTest.Open "SELECT * FROM Question WHERE TestID=" _
& TestID & " AND QuestionID=" & iQuestionID & ";", cnnTest
' Set our question info
strQuestionText = CStr(rsTest.Fields("Stem".Value)
' Get an array of answers
aAnswers = Array( _
CStr(rsTest.Fields("AnswerA".Value & "", _
CStr(rsTest.Fields("AnswerB".Value & "", _
CStr(rsTest.Fields("AnswerC".Value & "", _
CStr(rsTest.Fields("AnswerD".Value & "", _
CStr(rsTest.Fields("AnswerE".Value & "", _
CStr(rsTest.Fields("AnswerF".Value & "", _
CStr(rsTest.Fields("AnswerG".Value & "", _
CStr(rsTest.Fields("AnswerH".Value & "", _
CStr(rsTest.Fields("AnswerI".Value & "", _
CStr(rsTest.Fields("AnswerJ".Value & "")
' This is probably bad coding style, but too bad... it works!
For I = LBound(aAnswers) To UBound(aAnswers)
If aAnswers(I) = "" Then
ReDim Preserve aAnswers(I - 1)
Exit For
End If
Next ' I
' Close and dispose of our DB objects
rsTest.Close
Set rsTest = Nothing
cnnTest.Close
Set cnnTest = Nothing
' Now that we've got the variables set...
' show the appropriate question and choices
%>
<FONT SIZE="+2"><B><%= Session("TestName" %></B></FONT>
Progress Indicator:
<%
Const BAR_LENGTH = 160
If iQuestionID = 1 Then
' Since a 0 width is ignored by the browsers we need to remove the image altogether!
Response.Write "<IMG SRC=""./images/spacer_red.gif"" HEIGHT=""10"" WIDTH="""
Response.Write BAR_LENGTH
Response.Write """>
"
Else
Response.Write "<IMG SRC=""./images/spacer_blue.gif"" HEIGHT=""10"" WIDTH="""
Response.Write (BAR_LENGTH / iNumberOfQuestions) * (iQuestionID - 1)
Response.Write """>"
Response.Write "<IMG SRC=""./images/spacer_red.gif"" HEIGHT=""10"" WIDTH="""
Response.Write (BAR_LENGTH / iNumberOfQuestions) * (iNumberOfQuestions - (iQuestionID - 1))
Response.Write """>
"
End If
%>
Question <%= iQuestionID %> of <%= iNumberOfQuestions %>
<STRONG><%= iQuestionID %>.</STRONG> <%= strQuestionText %>
<STRONG>Choices:</STRONG>
<OL TYPE="A">
<%
For I = LBound(aAnswers) to UBound(aAnswers)
Response.Write "<LI><A HREF=""" & Request.ServerVariables("URL"
Response.Write "?qid=" & iQuestionID & "&sa=" & I & """>"
Response.Write aAnswers(I) & "</A></LI>" & vbCrLf
Next 'I
%>
</OL>
<%
End If
End If 'bAbort
%>
I have devleoped a quiz system that i will be using on my new site. I have the quiz script wrote, however, there are a number of quizzes that a user may take. These are stored in a MS Access database, each with a unique TestID. The quiz script at the moment works grand, however i have hardcoded the TestID in, which though it works it not efficient. What i want is for the user to select a book they have read froma drop down list box (which popoluates from the database Book Tabel), and upon submittance of this another list box appears which popoluates with tests associated to that book (via foreign key BookID in the Test Table).
Essentailly what i need to do is when the user clicks on the test they want to do(from the 2nd list box) the quiz page will load with the appropriate test.
Here is what i have created so far, but have run up against a brick wall! Can anyone be the saviour?! Thanks guys for your time.
bookdropdown.asp (which will provide drop boxes)
<!--#include file="Clssfd.asp"-->
<%
Dim rsBook, rsTest
Dim iRequestedID
' Some basic checking and cleaning of the input
iRequestedID = Trim(Request.QueryString("BookID")
iRequestedID = Replace(iRequestedID, "'", "''"
If IsNumeric(iRequestedID) Then
iRequestedID = CInt(iRequestedID)
Else
iRequestedID = 0
End If
' The form links back to this same file passing back the id
%>
<p>To add a question: Select the book that the question relates to</p>
<form action="bookdropdown.asp" method="GET">
<%
' Build our query for select box 1
strSQL= "SELECT * FROM Book ORDER BY Title"
Set rsBook = Server.CreateObject("ADODB.Recordset"
rsBook.Open strSQL, objConn
' build our first drop down with lists of books
If Not rsBook.EOF Then
rsBook.MoveFirst
%>
<SELECT NAME="BookID"><option>Select Book</option>
<%
' Loop through books
Do While Not rsBook.EOF
Response.Write "<option value="""
Response.Write rsBook.Fields("BookID"
Response.Write """"
If rsBook.Fields("BookID" = CInt(iRequestedID) Then
Response.Write "selected=""true"""
End If
Response.Write ">"
Response.Write Trim(rsBook.Fields("Title")
Response.Write "</option>" & vbCrLf
' Move to next record
rsBook.MoveNext
Loop
%>
</select>
<%
End If
rsBook.Close
Set rsBook = Nothing
' If a request for a specific id comes in, then build second select box
If iRequestedID <> 0 Then
strSQL = "SELECT * FROM Test WHERE BookId = " _
& iRequestedID & " ORDER BY TestName"
Set rsTest = Server.CreateObject("ADODB.Recordset"
rsTest.Open strSQL, objConn, adOpenForwardOnly, adLockOptimistic, adCmdText
' Build our drop down box of the tests
If Not rsTest.EOF Then
rsTest.MoveFirst
%>
<select name="TestID"><option>Select the test to add the question to</option>
<% ' Loop through tests
Do While Not rsTest.EOF
Response.Write "<option>"
Response.Write Trim(rsTest.Fields("TestName")
Response.Write "</option>" & vbCrLf
' Move to next record
rsTest.MoveNext
Loop
%>
</select>
<%
End If
' Close ADO objects we're finished with and free DB variables
rsTest.Close
Set rsTest = Nothing
End If
%>
<input type="submit" value="Submit" />
</form>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Then here is the quiz.asp page (Note where i hard coded the testID 'Const TestID = 4'
<!--#include file="Clssfd.asp"-->
<%
' Takes a integer parameter and converts it to the appropriate letter
Function GetLetterFromAnswerNumber(iInput)
Dim strTemp
Select Case iInput
Case 0
strTemp = "A"
Case 1
strTemp = "B"
Case 2
strTemp = "C"
Case 3
strTemp = "D"
Case 4
strTemp = "E"
Case 5
strTemp = "F"
Case 6
strTemp = "G"
Case 7
strTemp = "H"
Case 8
strTemp = "I"
Case 9
strTemp = "J"
End Select
GetLetterFromAnswerNumber = strTemp
End Function
' Create a fuction
Function GetAnswerFromAnswerString(iQuestionID, strAnswers)
Dim strTemp
Dim iOffset
' I use InStrRev since I want to retrieve the last entered value
' in case they went back and changed their mind.
' Find the location of the question number we want to use
iOffset = InStrRev(strAnswers, "|" & iQuestionID & "|", -1, 1)
' Get our answer by using the offset we just found and then moving
' right the length of the question indicator to arrive at the
' appropriate letter
strTemp = Mid(strAnswers, iOffset + Len("|" & iQuestionID & "|", 1)
' There's no way it should be anything else, but to be sure we
' convert it to a string and make sure it's uppercase
GetAnswerFromAnswerString = UCase(CStr(strTemp))
End Function
%>
<%
' Lets you run multiple Test from one DB by separating by TestID!
Const TestID = 4
' Now to all our other variables!
Dim cnnTest, rsTest 'DB objects if we use the DB for the info
Dim I 'our standard (improperly named) looping variable
Dim iNumberOfQuestion 'the number of questions in the test
Dim iQuestionID 'the question we're currently on
Dim strQuestionText 'text of the question to be asked
Dim aAnswers 'array of choices for the question to be asked
'if we hard code, then I also use it for the
'correct answers when I go to grade the quiz
Dim strAnswers 'stores the question numbers and response choices
'seperated by |'s
Dim iScore 'so we know how well the user did
Dim bAbort 'added after I had finished to account for closed sessions
Dim strResults 'another late addition for the each question breakdown!
bAbort = False 'set it to false since we only want to abort in certain cases
' If this is the first call to the quiz then init everything
' o/w retrieve values we need. We check by looking for the
' Question ID from the querystring.
If Request.QueryString("qid" = "" Then
' Retrieve and Set the Quiz Info
' Code to use DB!
' Create DB connection and connect to the DB
Set cnnTest = Server.CreateObject("ADODB.Connection"
cnnTest.Open objConn
' Create RS and query DB for quiz info
Set rsTest = Server.CreateObject("ADODB.Recordset"
rsTest.Open "SELECT * FROM Test WHERE TestID=" & TestID & ";", cnnTest
' Set our session vars
Session("TestName" = CStr(rsTest.Fields("TestName".Value)
Session("NumberOfQuestions" = CInt(rsTest.Fields("NumberOfQuestions".Value)
Session("PercentageToPass" = CInt(rsTest.Fields("PercentageToPass".Value)
' Close and dispose of our DB objects
rsTest.Close
Set rsTest = Nothing
cnnTest.Close
Set cnnTest = Nothing
' Set our question indicator to 1 and init our answer string
iQuestionID = 1
Session("AnswerString" = "|"
Else
'Check to be sure we've still got a session!
If Session("AnswerString" = "" Then
Response.Write "I'm sorry, but you've taken too long. You can start over by "
Response.Write "clicking <A HREF=""" & Request.ServerVariables("URL" & """>here</A>."
'to get the script to complete declared and set a Flag
'Response.End
bAbort = True
End If
' Get the number of the question we're processing
iQuestionID = CInt(Request.QueryString("qid")
' Log selected answer to last question
Session("AnswerString" = Session("AnswerString" & iQuestionID & "|" & _
GetLetterFromAnswerNumber(CInt(Request.QueryString("sa")) & "|"
' Increment question identifier
iQuestionID = iQuestionID + 1
End If
' If session has expired then skip all the code.
' Equivalently, only run all the code if it hasn't!
If Not bAbort Then
' Set this to a local variable to avoid accessing the collection each time
' This isn't required, but makes it easier for me to access and
' supposedly speeds it up... I'm not sure how much, but it can't hurt!
iNumberOfQuestions = Session("NumberOfQuestions"
' Check to see it the quiz is over. If so then show results, o/w
' ask the next question
If iQuestionID > iNumberOfQuestions Then
' Process results and show end quiz status report
' Done for the same reason as for iNumberOfQuestions a few lines above
strAnswers = Session("AnswerString"
' Useful for debugging
'Response.Write strAnswers & "
" & vbCrLf & "
" & vbCrLf
' Bug hunting once again... I didn't even come across any real bugs on this trip!
' Could you imagine the ammo I'd take if it was real hunting I was doing!
'For I = 1 to iNumberOfQuestions
' Response.Write GetAnswerFromAnswerString(I, strAnswers) & "
" & vbCrLf
'Next 'I
' Retrieve Correct Answers and compare to the entered ones
' Code to use DB!
' Create DB connection and connect to the DB
Set cnnTest = Server.CreateObject("ADODB.Connection"
cnnTest.Open objConn
' Create RS and query DB for quiz info
Set rsTest = Server.CreateObject("ADODB.Recordset"
' Specify 3, 1 (Static, Read Only)
rsTest.Open "SELECT * FROM Question WHERE TestID=" & TestID & _
" ORDER BY QuestionID;", cnnTest, 3, 1
iScore = 0
I = 1
Do While Not rsTest.EOF
If UCase(CStr(rsTest.Fields("CorrectAnswer".Value)) = _
GetAnswerFromAnswerString(I, strAnswers) Then
iScore = iScore + 1
' This and the Else could be used to output a
' correctness status for each question
' Also useful for bug hunting!
'Response.Write "Right" & "
" & vbCrLf
Else
'Response.Write "Wrong" & "
" & vbCrLf
strResults = strResults & I & ", "
End If
I = I + 1
rsTest.MoveNext
Loop
' Close and dispose of our DB objects
rsTest.Close
Set rsTest = Nothing
cnnTest.Close
Set cnnTest = Nothing
' Convert score to a percentage rounded to the whole number
iScore = Round((iScore / iNumberOfQuestions) * 100)
%>
<FONT SIZE="+2"><B><%= Session("TestName" %></B></FONT>
<%
If iScore >= Session("PercentageToPass" Then
Response.Write "Congratulations! You've passed the quiz with a score of "
Response.Write iScore & "%.
" & vbCrLf
Else
Response.Write "Sorry! You needed to achieve a score of "
Response.Write Session("PercentageToPass" & "% or higher to pass. "
Response.Write "Unfortunately, your score was only " & iScore & "%. "
Response.Write "You can take the test again by clicking <A HREF="""
Response.Write Request.ServerVariables("URL" & """>here</A>.
" & vbCrLf
End If
Response.Write "
" & vbCrLf
If Len(strResults) <> 0 Then
Response.Write "You missed the following questions: " & Left(strResults, Len(strResults) - 2)
Response.Write "
" & vbCrLf
End If
'Response.Write iScore & "%"
' This is also where you could log the results if you wanted to.
' In it's simplest form, you would simply log strAnswers to a file,
' but you could format little "report cards" or log the result to a
' separate data source.
Else
' Retrieve and Set the Question Info
' Code to use DB!
' Create DB connection and connect to the DB
Set cnnTest = Server.CreateObject("ADODB.Connection"
cnnTest.Open objConn
' Create RS and query DB for quiz info
Set rsTest = Server.CreateObject("ADODB.Recordset"
rsTest.Open "SELECT * FROM Question WHERE TestID=" _
& TestID & " AND QuestionID=" & iQuestionID & ";", cnnTest
' Set our question info
strQuestionText = CStr(rsTest.Fields("Stem".Value)
' Get an array of answers
aAnswers = Array( _
CStr(rsTest.Fields("AnswerA".Value & "", _
CStr(rsTest.Fields("AnswerB".Value & "", _
CStr(rsTest.Fields("AnswerC".Value & "", _
CStr(rsTest.Fields("AnswerD".Value & "", _
CStr(rsTest.Fields("AnswerE".Value & "", _
CStr(rsTest.Fields("AnswerF".Value & "", _
CStr(rsTest.Fields("AnswerG".Value & "", _
CStr(rsTest.Fields("AnswerH".Value & "", _
CStr(rsTest.Fields("AnswerI".Value & "", _
CStr(rsTest.Fields("AnswerJ".Value & "")
' This is probably bad coding style, but too bad... it works!
For I = LBound(aAnswers) To UBound(aAnswers)
If aAnswers(I) = "" Then
ReDim Preserve aAnswers(I - 1)
Exit For
End If
Next ' I
' Close and dispose of our DB objects
rsTest.Close
Set rsTest = Nothing
cnnTest.Close
Set cnnTest = Nothing
' Now that we've got the variables set...
' show the appropriate question and choices
%>
<FONT SIZE="+2"><B><%= Session("TestName" %></B></FONT>
Progress Indicator:
<%
Const BAR_LENGTH = 160
If iQuestionID = 1 Then
' Since a 0 width is ignored by the browsers we need to remove the image altogether!
Response.Write "<IMG SRC=""./images/spacer_red.gif"" HEIGHT=""10"" WIDTH="""
Response.Write BAR_LENGTH
Response.Write """>
"
Else
Response.Write "<IMG SRC=""./images/spacer_blue.gif"" HEIGHT=""10"" WIDTH="""
Response.Write (BAR_LENGTH / iNumberOfQuestions) * (iQuestionID - 1)
Response.Write """>"
Response.Write "<IMG SRC=""./images/spacer_red.gif"" HEIGHT=""10"" WIDTH="""
Response.Write (BAR_LENGTH / iNumberOfQuestions) * (iNumberOfQuestions - (iQuestionID - 1))
Response.Write """>
"
End If
%>
Question <%= iQuestionID %> of <%= iNumberOfQuestions %>
<STRONG><%= iQuestionID %>.</STRONG> <%= strQuestionText %>
<STRONG>Choices:</STRONG>
<OL TYPE="A">
<%
For I = LBound(aAnswers) to UBound(aAnswers)
Response.Write "<LI><A HREF=""" & Request.ServerVariables("URL"
Response.Write "?qid=" & iQuestionID & "&sa=" & I & """>"
Response.Write aAnswers(I) & "</A></LI>" & vbCrLf
Next 'I
%>
</OL>
<%
End If
End If 'bAbort
%>