Dim question As String
Dim a(4) As String ' I assume the answers you retrieve are text
question = SQL1.ExecQuerySingleResult("SELECT question FROM trivia where ID = 116")
a(0) = SQL1.ExecQuerySingleResult("SELECT answer FROM trivia where ID = 116")
a(1) = SQL1.ExecQuerySingleResult("SELECT wrong1 FROM trivia where ID = 116")
a(2) = SQL1.ExecQuerySingleResult("SELECT wrong2 FROM trivia where ID = 116")
a(3) = SQL1.ExecQuerySingleResult("SELECT wrong3 FROM trivia where ID = 116")
lblQuestion.Text = question
Dim i, k, x As Int
Dim answers(4) As Int
For i = 0 To 3
answers(i) = i + 1
Next
For i = 0 To 3
k = Rnd(i, 4)
x = answers(i)
answers(i) = answers(k)
answers(k) = x
Next
answer1.Text = a(answers(0)) 'assuming answer1 etc are button names
answer2.Text = a(answers(1))
answer3.Text = a(answers(2))
answer4.Text = a(answers(3))
Dim question As String
Dim a(4) As Int
question = SQL1.ExecQuerySingleResult("SELECT question FROM trivia where ID = 116")
a(0) = SQL1.ExecQuerySingleResult("SELECT answer FROM trivia where ID = 116")
a(1) = SQL1.ExecQuerySingleResult("SELECT wrong1 FROM trivia where ID = 116")
a(2) = SQL1.ExecQuerySingleResult("SELECT wrong2 FROM trivia where ID = 116")
a(3) = SQL1.ExecQuerySingleResult("SELECT wrong3 FROM trivia where ID = 116")
lblQuestion.Text = question
Dim i, k, x As Int
For i = 0 To 3
k = Rnd(i, 4)
x = a(i)
a(i) = a(k)
a(k) = x
Next
answer1.text = "answer " & a(0) 'assuming answer1 etc are button names
answer2.Text = "answer " + a(1)
answer3.Text = "answer " + a(2)
answer4.Text = "answer " + a(3)
Now I am getting Line 117
K= Rnd(i,3)
java.lang.illegalargumentexception
k = Rnd(i, 4)
For i = 0 To 3
answers(i) = i + 1
Next
For i = 0 To 3
answers(i) = i
Next
Another question. I have 73 questions. Generating the random number is not a problem. What I need to do is once that number is used it gets placed into an array or variable or something and the next time the button is clicked it generates a random number between 0 and 73 excluding the numbers that have already been generated. How would I do that?
Dim NotUsed As Boolean
Dim i As Int
NotUsed = False
Do Until NotUsed = True
NewNumber = Rnd (0, 74)
NotUsed = True
If UsedNumbers.Size > 0 Then
For i = 0 To UsedNumbers.Size -1
If UsedNumbers.Get (i) = NewNumber Then NotUsed = False
Next
End If
Loop
UsedNumbers.Add (NewNumber)
' you can now use NewNumber as it is unique
Dim NumberList As List
Dim i As Int
NumberList.Clear ' ensure the list is empty
For i = 1 To 73
NumberList.Add (i) ' add the numbers to the list
Next
Dim i As Int
Dim NewNumber As Int
i = Rnd (0, NumberList.Size ) ' random pointer to somewhere in the list
NewNumber = NumberList.Get (i) ' get the number
NumberList.RemoveAt (i) ' remove the number from the list
' you can now use NewNumber for your question. Note this does not check for the list being empty.
Yes! :icon_clap: That's the way of doing it I was trying to remember but couldn't!
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?