owensoranges
01-08-2007, 09:10 PM
Hi, i'm very new to Visual Basic and am trying to make a simple True or False game about pythons for my youngest son who is fascinated by theml. I've managed to get quite far by using various tutorials but now have hit a problem: sometimes a question is repeated, and sometimes instead of True or False appearing, i'll get False and False or True and True. How do i remedy this?? Attached is the code. Hope someone can help! Thank you
Private Sub cmdNext_Click()
Dim VUsed(10) As Integer, I As Integer, J As Integer
Dim Index(2) As Integer
'Generate the next question
cmdNext.Enabled = False
Answer = Int(Rnd * 10) + 1
'Display selected question
lblQuestion.Caption = Question(Answer)
'Vused array to see which answers have been selected
For I = 1 To 10
VUsed(I) = 0
Next I
'Pick two different answer choices indices (J) at random
'Stored in the index array
For I = 1 To 2
'Find index not used yet and not the answer
Do
J = Int(Rnd * 10) + 1
Loop Until VUsed(J) = 0 And J <> Answer
VUsed(J) = 1
Index(I) = J
Next I
'replace one index (at random) with correct answer
Index(Int(Rnd * 2) + 1) = Answer
'Display multiple choice answers in label boxes
For I = 1 To 2
lblChoice(I).Caption = Choice(Index(I))
Next I
End Sub
Private Sub cmdNext_Click()
Dim VUsed(10) As Integer, I As Integer, J As Integer
Dim Index(2) As Integer
'Generate the next question
cmdNext.Enabled = False
Answer = Int(Rnd * 10) + 1
'Display selected question
lblQuestion.Caption = Question(Answer)
'Vused array to see which answers have been selected
For I = 1 To 10
VUsed(I) = 0
Next I
'Pick two different answer choices indices (J) at random
'Stored in the index array
For I = 1 To 2
'Find index not used yet and not the answer
Do
J = Int(Rnd * 10) + 1
Loop Until VUsed(J) = 0 And J <> Answer
VUsed(J) = 1
Index(I) = J
Next I
'replace one index (at random) with correct answer
Index(Int(Rnd * 2) + 1) = Answer
'Display multiple choice answers in label boxes
For I = 1 To 2
lblChoice(I).Caption = Choice(Index(I))
Next I
End Sub