JAVAScript Code Example 1 Click here to contact us JAVAScript Code Example 2 Login Code Sample <%@ Language=VBScript %> <% if not isempty(Request.Form("LogIn")) then set conn = server.createobject ("adodb.connection") conn.open "ASPBook", "sa", "yourpassword" set RSUser = conn.Execute("select UserName from C1Login " _ & "where UserName = '" & Request.Form("UserName") _ & "' and Password = '" & Request.Form("Password") _ & "'") if RSUser.EOF then TheMessage = "You have entered an incorrect login. " _ & "Please try again." else TheMessage = "You are now logged in!" end if else TheMessage = "Please enter your user name and password below." end if %> Quiz Class Code Public Function GetQuestion(QuestionID) Dim RSQuestion As ADODB.Recordset Set RSQuestion = Conn.Execute("select Question from C1Questions " _ & "where QuestionID = " & QuestionID) If RSQuestion.EOF Then GetQuestion = "NA" Else GetQuestion = RSQuestion("Question") End If End Function Public Function GetAnswer(QuestionID) Dim RSAnswers As ADODB.Recordset Dim TempList As String Set RSAnswers = Conn.Execute("select Answer from C1Answers " _ & "where QuestionID = " & QuestionID) Do Until RSAnswers.EOF TempList = TempList & "" RSAnswers.MoveNext Loop GetAnswer = TempList End Function Public Function CheckAnswer(QuestionID, AnswerText) Dim RSAnswer As ADODB.Recordset Set RSAnswer = Conn.Execute("select Answer from C1Questions " _ & "where QuestionID = " & QuestionID) If RSAnswer("Answer") = AnswerText Then CheckAnswer = 1 Else CheckAnswer = 0 End If End Function Private Sub Class_Initialize() Conn.Open "ASPBook", "sa", "yourpassword" End Sub Quiz ASP Code <%@ Language=VBScript %> <% set objQuiz = server.CreateObject("SampleServer.Quiz") if isempty(Request.Form("Calculate")) then CurrentQuestion = 1 QuestionsTaken = 0 NumberCorrect = 0 else if objQuiz.CheckAnswer(Request.Form("CurrentQuestion"), _ Request.Form("Answer")) = 1 then NumberCorrect = Request.Form("NumberCorrect") + 1 else NumberCorrect = Request.Form("NumberCorrect") end if QuestionsTaken = Request.Form("QuestionsTaken") + 1 CurrentQuestion = Request.Form("CurrentQuestion") + 1 end if QuestionText = objQuiz.GetQuestion(CurrentQuestion) if QuestionText = "NA" then TheMessage = "Quiz: Complete" else TheMessage = "Quiz: In Progress" AnswerText = objQuiz.GetAnswer(CurrentQuestion) end if %>

<% response.write QuestionText %>

<% Response.Write TheMessage %>
Score: <% Response.Write NumberCorrect %> out of <% Response.Write QuestionsTaken %>