Nicodemas
03-27-2003, 05:48 AM
Here's the situation:
I have a database that has 45 questions, and four Answer fields (Answer1, Answer2, Answer3, Answer4).
Another field is called CorrectAnswer (which is always set to one because the correct answer is always Answer1's value.
Thing is, I want to display these questions in random order.
Well, I've got that part down with the code below, but sometimes it repeats a question.
This is what I am trying NOT to do.
I thought about sticking the random number in an array and test for duplicates, but I can't seem to do it, and that seems a bit overly complicated.
Think you can get it workin'? My brain is toast...
<%
Randomize Timer ' SET Rnd SEED = TIMER
intTotalQ = RS.RecordCount 'RETURNS THE TOTAL NUMBER OF RECORDS IN THE RECORDSET
For x = 1 To intTotalQ
intRnd = (x * rnd)+rnd ' SET intRnd = A RANDOM NUMBER BETWEEN 1 AND 45
RS.Move intRnd 'MOVE TO THAT RANDOM NUMBER
Response.Write("<TR>") ' WRITE OUT A TABLE ROW
Response.Write("<TD ID='Ques'>") 'GIVE IT THE GREEN QUESTION COLOR
Response.Write(x & ". " & RS("Question")) 'WRITE THE QUESTION
Response.Write("</TD>") 'CLOSE THE CELL UP
Response.Write("</TR><TR>") 'START NEW ROWS
Response.Write("<TD ID='Ans'>") ' FORMAT IT WITH THE ANSWER STYLE (THE OLIVE COLOR)
For i = 1 To 4 'FOR EACH FIELD NAMED "ANSWER#"
If Not RS("Answer"&i) = "" Then 'CHECK IF THE FIELD IS -NULL-. IF IT IS NOT -NULL-
Response.Write("<INPUT TYPE='radio' NAME='strAns" & RS("QuestionID") & "' VALUE='" &_
& RS("Answer"&i) & "'>" & RS("Answer"&i) & "<BR>") 'WRITE A RADIO W/ ANSWER[i]
End If
Next
Response.Write("</TD></TR>")
If RS.EOF="True" Then 'IF THE RANDOM NUMBERS RUN PAST THE intTotalQ
x= x-1 'SUBTRACT ONE FROM THE COUNT
RS.MoveFirst 'MOVE TO THE FIRST RECORD IN THE SET
End If
Next
%>
I have a database that has 45 questions, and four Answer fields (Answer1, Answer2, Answer3, Answer4).
Another field is called CorrectAnswer (which is always set to one because the correct answer is always Answer1's value.
Thing is, I want to display these questions in random order.
Well, I've got that part down with the code below, but sometimes it repeats a question.
This is what I am trying NOT to do.
I thought about sticking the random number in an array and test for duplicates, but I can't seem to do it, and that seems a bit overly complicated.
Think you can get it workin'? My brain is toast...
<%
Randomize Timer ' SET Rnd SEED = TIMER
intTotalQ = RS.RecordCount 'RETURNS THE TOTAL NUMBER OF RECORDS IN THE RECORDSET
For x = 1 To intTotalQ
intRnd = (x * rnd)+rnd ' SET intRnd = A RANDOM NUMBER BETWEEN 1 AND 45
RS.Move intRnd 'MOVE TO THAT RANDOM NUMBER
Response.Write("<TR>") ' WRITE OUT A TABLE ROW
Response.Write("<TD ID='Ques'>") 'GIVE IT THE GREEN QUESTION COLOR
Response.Write(x & ". " & RS("Question")) 'WRITE THE QUESTION
Response.Write("</TD>") 'CLOSE THE CELL UP
Response.Write("</TR><TR>") 'START NEW ROWS
Response.Write("<TD ID='Ans'>") ' FORMAT IT WITH THE ANSWER STYLE (THE OLIVE COLOR)
For i = 1 To 4 'FOR EACH FIELD NAMED "ANSWER#"
If Not RS("Answer"&i) = "" Then 'CHECK IF THE FIELD IS -NULL-. IF IT IS NOT -NULL-
Response.Write("<INPUT TYPE='radio' NAME='strAns" & RS("QuestionID") & "' VALUE='" &_
& RS("Answer"&i) & "'>" & RS("Answer"&i) & "<BR>") 'WRITE A RADIO W/ ANSWER[i]
End If
Next
Response.Write("</TD></TR>")
If RS.EOF="True" Then 'IF THE RANDOM NUMBERS RUN PAST THE intTotalQ
x= x-1 'SUBTRACT ONE FROM THE COUNT
RS.MoveFirst 'MOVE TO THE FIRST RECORD IN THE SET
End If
Next
%>