0

我有很多这样的问题:

Dim Questions(25) As TheQuestions

Function loadQuestions()

    Questions(0).Question = "Which of these words are an adjective?"
    Questions(0).option1 = "Dog"
    Questions(0).option2 = "Beautiful"
    Questions(0).option3 = "Steven"
    Questions(0).option4 = "Bird"
    Questions(0).Answer = "B"

    Questions(1).Question = "What's the adjective in this sentence:" & vbCrLf & "'Kelly handled the breakable glasses very carefully'"
    Questions(1).option1 = "Kelly"
    Questions(1).option2 = "Handled"
    Questions(1).option3 = "Carefully"
    Questions(1).option4 = "Breakable"
    Questions(1).Answer = "D"

    Questions(2).Question = "What's the adjective in this sentence: 'Karen is a graceful dancer'"
    Questions(2).option1 = "Is"
    Questions(2).option2 = "Graceful"
    Questions(2).option3 = "Dancer"
    Questions(2).option4 = "Tanya"
    Questions(2).Answer = "B"
    ...

我找到了一种成功随机化问题的方法,但我能否确保显示正确的四个潜在答案以及正在显示的问题?

下面是调用获取问题的函数的代码,然后将其显示在标签(lblQuestion)中,我猜我正在寻找的代码需要去哪里:

Function GetQuestion(ByVal intQuestion As Integer)

    tmrOne.Start()

        If questionNumber < 25 Then
            lblQuestionNumber.Text = "Question" & " " & questionNumber
            lblQuestion.Text = Questions(intQuestion).Question
            btnAnswerA.Text = Questions(intQuestion).option1
            btnAnswerB.Text = Questions(intQuestion).option2
            btnAnswerC.Text = Questions(intQuestion).option3
            btnAnswerD.Text = Questions(intQuestion).option4
            strAnswer = Questions(intQuestion).Answer
            questionNumber = questionNumber + 1
            btnAnswerA.BackColor = Color.White
            btnAnswerB.BackColor = Color.White
            btnAnswerC.BackColor = Color.White
            btnAnswerD.BackColor = Color.White
            btnAnswerA.Enabled = True
            btnAnswerB.Enabled = True
            btnAnswerC.Enabled = True
            btnAnswerD.Enabled = True
            Return intQuestion
        Else
            MsgBox("You have finished")
            End
        End If

End Function

我用这个:

lblQuestion.Text = Questions(random.Next(25)).Question

它将问题随机化,但我如何得到它以便四个可能的答案与正确的问题一起显示,就像上面有四个选项的数组一样。

非常感谢!

4

1 回答 1

1

代替:

lblQuestion.Text = Questions(random.Next(25)).Question

我认为您只需要保存随机数并这样做:

dim questionChosen as int

questionChosen = random.Next(25)
lblQuestion.Text = Questions(questionChosen).Question

然后使用 Questions(questionChosen).WhateverYouNeed 更新其余字段

于 2013-08-24T16:05:50.370 回答