Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Can anyone suggest a randomizer??

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,816
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Can anyone suggest a randomizer??
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Can anyone suggest a randomizer?? - 3/30/2003 11:51:00 AM   
  Portmoon

 

Posts: 4
Score: 0
Joined: 2/24/2003
From:
Status: offline
Hi there!

The following piece of code is based on a quiz.
It currently takes 'all' the records (questions and 4 corresponding answer choices)
from the databaseand displays them on a web page.
The database is made up of 6 fields, 1 question, 4 answer and 1 correctID field that
holds the number that corresponds to the correct answer position in each case.
When the quiz is completed the SUB Mark() function calculates the score and displays questions,
correct answers and the score on another page.
What I wanted to know was how I could randomize the quiz.
i.e Retrieve 10 random questions from a database table of 30 thirty questions
and display them and their answers on a page?? (The file is called quiz.asp)

Any help and suggestions would be greatrly appreciated!!

Thanks,

Portmoon.



<%
' On Error Resume Next

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("myDatabase.mdb")
SQL = "SELECT * Quiz, conn, 3"
Set rs = conn.Execute(SQL)

IF Request.Form.Count = 0 THEN
CALL List
ELSE CALL Mark
END IF

rs.close
conn.close
Set rs = Null
Set conn = Null

%>

<% SUB List() %>
<% session("referer") = Request.ServerVariables("HTTP_REFERER") %>



    <% DO WHILE NOT rs.eof %>
  1. <%= rs("question")%>

    <%
    FOR i = 1 to 5
    choice = rs.fields(i+1).value
    IF choice <> "" THEN
    %>
    " VALUE="<%= i %>">
    <%= choice %>


    <%
    END IF
    NEXT
    %>


    <%
    rs.MoveNext
    LOOP
    %>




<% END SUB %>

<%
SUB Mark()

correctCount = 0
total = 0
%>


<%
FOR EACH x IN Request.Form
DO WHILE rs("questionID") <> CInt(x)
rs.MoveNext
LOOP
correctID = rs("correctID")
chosenID = CInt(Request.Form(x))
%>


The question was: <%= rs("question") %>

Your choice was: <%= rs.fields(chosenID+1).value %>.

<%
IF chosenID = correctID THEN
correctCount = correctCount + 1
%>
Your answer is correct.

<%
ELSE
%>
The correct answer is: <%= rs.fields(correctID+1).value %>.

Feedback: <%= rs("comment") %>.


<%
END IF
NEXT


rs.MoveFirst
DO WHILE NOT rs.eof
total = total + 1
rs.MoveNext
LOOP
%>


You answered correctly <%= correctCount %> / <%= total %> questions
and your score is <%= Round(correctCount / total * 100) %>%

">End Quiz.


<% END SUB %>

 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Can anyone suggest a randomizer?? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts