📄 quiz.asp
字号:
iScore = 0
For I = 1 to iNumberOfQuestions
If UCase(CStr(aAnswers(I - 1))) = _
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" & "<BR>" & vbCrLf
Else
'Response.Write "Wrong" & "<BR>" & vbCrLf
strResults = strResults & I & ", "
End If
Next 'I
End If
' Convert score to a percentage rounded to the whole number
iScore = Round((iScore / iNumberOfQuestions) * 100)
%>
<FONT SIZE="+2"><B><%= Session("QuizName") %></B></FONT><BR>
<BR>
<%
If iScore >= Session("PercentageToPass") Then
Response.Write "Congratulations! You've passed the quiz with a score of "
Response.Write iScore & "%.<BR>" & 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>.<BR>" & vbCrLf
End If
Response.Write "<BR>" & vbCrLf
If Len(strResults) <> 0 Then
Response.Write "You missed the following questions: " & Left(strResults, Len(strResults) - 2)
Response.Write "<BR>" & 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
If USE_DB_FOR_INFO Then
' Code to use DB!
' Create DB connection and connect to the DB
Set cnnQuiz = Server.CreateObject("ADODB.Connection")
cnnQuiz.Open DB_CONN_STRING
' Create RS and query DB for quiz info
Set rsQuiz = Server.CreateObject("ADODB.Recordset")
rsQuiz.Open "SELECT * FROM questions WHERE quiz_id=" _
& QUIZ_ID & " AND question_number=" & iQuestionNumber & ";", cnnQuiz
' Set our question info
strQuestionText = CStr(rsQuiz.Fields("question_text").Value)
' Get an array of answers
aAnswers = Array( _
CStr(rsQuiz.Fields("answer_a").Value & ""), _
CStr(rsQuiz.Fields("answer_b").Value & ""), _
CStr(rsQuiz.Fields("answer_c").Value & ""), _
CStr(rsQuiz.Fields("answer_d").Value & ""), _
CStr(rsQuiz.Fields("answer_e").Value & ""), _
CStr(rsQuiz.Fields("answer_f").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
rsQuiz.Close
Set rsQuiz = Nothing
cnnQuiz.Close
Set cnnQuiz = Nothing
Else
' If we're not going to the DB, hard code in values here!
' BEGIN HARD CODE
Select Case iQuestionNumber
Case 1
strQuestionText = "What does ASP stand for?"
aAnswers = Array( _
"Active Server Pages", _
"Additional Sensory Perception", _
"Accidental Script Problem", _
"Altruistically Solving Problems", _
"Additional Sleeping Preferred", _
"Any Solution Possible")
Case 2
strQuestionText = "What command is <%= %> equivalent to?"
aAnswers = Array( _
"Response.Write", _
"Request.Write", _
"Referer.Write", _
"Redirect.Write", _
"Reasonably.Write", _
"Damn It I'm Right!")
Case 3
strQuestionText = "What does "Option Explicit" do?"
aAnswers = Array( _
"Requires explicit variable declaration", _
"Makes the computer give you additional errors", _
"Converts a PG rated programming language into one rated NC-17")
Case 4
strQuestionText = "Which of the following is not a valid "
strQuestionText = strQuestionText & "VBScript looping statement?"
aAnswers = Array( _
"Do...Loop", _
"While...Wend", _
"For...Next", _
"For Each...Next", _
"Just do this 10 times you stupid computer!")
Case 5
strQuestionText = "What language can you not use to write ASP?"
aAnswers = Array( _
"VBScript", _
"JavaScript (JScript)", _
"PerlScript", _
"SuperScript")
Case 6
strQuestionText = "Where does ASP code execute?"
aAnswers = Array( _
"On the web server", _
"In the client's browser", _
"On any machine it wants to", _
"Reportedly somewhere in Washington State")
Case 7
strQuestionText = "Which set of acronyms is not associated with ASP?"
aAnswers = Array( _
"CDO, CDONTS", _
"ADO, RDS, DAO, ODBC", _
"IIS, PWS, MMC", _
"ADSI, XML", _
"BÖC, OU812, GNR, BTO")
Case 8
strQuestionText = "Which of the following is not something you can get "
strQuestionText = strQuestionText & "from the Request collection?"
aAnswers = Array( _
"Cookies", _
"Form", _
"QueryString", _
"ServerVariables", _
"Beer", _
"ClientCertificate")
Case 9
strQuestionText = "What will this script output when run?<BR><BR><%<BR>"
strQuestionText = strQuestionText & "Dim aTempArray<BR>Dim I<BR>"
strQuestionText = strQuestionText & "aTempArray = Array(1, 2, 3)<BR>"
strQuestionText = strQuestionText & "For I = LBound(aTempArray) To "
strQuestionText = strQuestionText & "Ubound(aTempArray)<BR>"
strQuestionText = strQuestionText & " "
strQuestionText = strQuestionText & "Response.Write I & " "<BR>"
strQuestionText = strQuestionText & "Next 'I<BR>%><BR>"
aAnswers = Array( _
"0 1 2", _
"1 2 3", _
"0<BR>1<BR>2<BR>", _
"1<BR>2<BR>3<BR>")
Case 10
strQuestionText = "What is the URL of the best ASP web site?"
aAnswers = Array("http://www.asp101.com (yeah... like we'd put any other choices here!)")
End Select
' END HARD CODE
End If
' Now that we've got the variables set...
' show the appropriate question and choices
%>
<FONT SIZE="+2"><B><%= Session("QuizName") %></B></FONT><BR>
<BR>
Progress Indicator:
<%
Const BAR_LENGTH = 160
If iQuestionNumber = 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 """><BR>"
Else
Response.Write "<IMG SRC=""./images/spacer_blue.gif"" HEIGHT=""10"" WIDTH="""
Response.Write (BAR_LENGTH / iNumberOfQuestions) * (iQuestionNumber - 1)
Response.Write """>"
Response.Write "<IMG SRC=""./images/spacer_red.gif"" HEIGHT=""10"" WIDTH="""
Response.Write (BAR_LENGTH / iNumberOfQuestions) * (iNumberOfQuestions - (iQuestionNumber - 1))
Response.Write """><BR>"
End If
%>
Question <%= iQuestionNumber %> of <%= iNumberOfQuestions %><BR>
<BR>
<STRONG><%= iQuestionNumber %>.</STRONG> <%= strQuestionText %><BR>
<BR>
<STRONG>Choices:</STRONG>
<OL TYPE="A">
<%
For I = LBound(aAnswers) to UBound(aAnswers)
Response.Write "<LI><A HREF=""" & Request.ServerVariables("URL")
Response.Write "?qid=" & iQuestionNumber & "&sa=" & I & """>"
Response.Write aAnswers(I) & "</A></LI>" & vbCrLf
Next 'I
%>
</OL>
<%
End If
End If 'bAbort
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -