I have a database I pull a single record from. In the record is a question and 4 answers. 3 being incorrect and one being correct. I have 4 buttons. I need to populate the text of each button with random answer values. Right now I am places the values into 4 variables. I was thinking of doing something like this:
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, j, 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
' For j = 0 To 3
' Holdings(j).Clear
' k = j*13
' For i = 0 To 12
' Holdings(j).Add(answers(i + k))
' Next
' Holdings(j).Sort(True)
answer1.text = a(answers(k))
answer2.Text = "answer" + rand
answer3.Text = "answer" + rand
answer4.Text = "answer" + rand
I know that this will duplicate. I already have a process to prevent that but didn't want to put all the code here.
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, j, 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
' For j = 0 To 3
' Holdings(j).Clear
' k = j*13
' For i = 0 To 12
' Holdings(j).Add(answers(i + k))
' Next
' Holdings(j).Sort(True)
answer1.text = a(answers(k))
answer2.Text = "answer" + rand
answer3.Text = "answer" + rand
answer4.Text = "answer" + rand
I know that this will duplicate. I already have a process to prevent that but didn't want to put all the code here.