ram_son Level: Graduate
 Registered: 01-05-2005 Posts: 11
|
Re: adapting code for form 2.0
Thanks...That didn't work.
However I was told to change the CheckLabel to CheckAnswer and that seems to have solved the problem.
Maybe you can help me with anoyher issue if you don't mind... It's about choosing the questions randomly.It seems like the choice of question is not really that random as it always starts with the same choice and seems to folow a predictable pattern. Below is the code that I think is responsible for the choices ... the way somebody helped me to
create.
Let me know how I can improve that..
--------------------
Private Sub LoadQuestion()
Set DB = OpenDatabase("D:\....file.mdb")
Set RS = DB.OpenRecordset("select * from qRandomAnswers")
Dim op(1 To 3) As String ' , op2 As String, op3 As String
Dim randomArr(0 To 3) As String
Dim I As Integer, rc As Long
' clear all the labels
lbltext.Caption = ""
Lbl1.Caption = ""
Lbl2.Caption = ""
Lbl3.Caption = ""
Lbl4.Caption = ""
' initialize the system randomizer, in order to randomly
' execute the query
Randomize
' load the recordset from the query
' fills the variables
qt = RS.Fields("QuestionText").Value
ca = RS.Fields("CorrectAnswer").Value
' load the temporary variables with the optional wrong values
RS.MoveFirst
Do While Not RS.EOF
I = I + 1
op(I) = RS.Fields("Correct").Value
RS.MoveNext
Loop
rc = I + 1 ' simulates a records counter, as this recordset
' doesn't expose a RecordCount property to read
' fill the text label
lbltext.Caption = qt
' randomize the four answers from the query into an array
I = Int((rc - 1 + 1) * Rnd + 1) - 1 ' generates a random number 0-3
randomArr(I) = ca
randomArr((I + 1) Mod rc) = op(1)
randomArr((I + 2) Mod rc) = op(2)
randomArr((I + 3) Mod rc) = op(3)
' fills the array values into the labels
Lbl1.Caption = randomArr(0)
Lbl2.Caption = randomArr(1)
Lbl3.Caption = randomArr(2)
Lbl4.Caption = randomArr(3)
' I'm forced to use four separate labels, as MSAccess doesn't support
' arrays of controls. In VB I'd create an array of four labels
End Sub
|