1 Replies - 284 Views - Last Post: 26 August 2013 - 09:32 AM Rate Topic: -----

#1 kat595  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-July 13

How can you stop an array from repeating a question? Visual Basic 2010

Posted 26 August 2013 - 09:30 AM

I have an array that's set up to hold 25 questions, for which the possible answers are displayed on separate buttons.

Code for array is set up like below:

Questions(0).Question = "Question goes here
        Questions(0).option1 = "Answer 1"
        Questions(0).option2 = "Answer 2"
        Questions(0).option3 = "Answer 3"
        Questions(0).option4 = "Answer 4"
        Questions(0).Answer = "B"

        Questions(1).Question = "Second question goes here"
        Questions(1).option1 = "Answer 1"
        Questions(1).option2 = "Answer 2"
        Questions(1).option3 = "Answer 3"
        Questions(1).option4 = "Answer 4"
        Questions(1).Answer = "D"
        ...



I have randomized the array, as I don't want the same questions in the same order every time that it's played. For this, I have used the code below:


 Function GetQuestion(ByVal intQuestion As Integer)

        tmrOne.Start()

        If questionNumber < 11 Then
            lblQuestionNumber.Text = "Question" & " " & questionNumber
            Dim questionChosen As Integer
                questionChosen = random.Next(25)
                lblQuestion.Text = Questions(questionChosen).Question
                btnAnswerA.Text = Questions(questionChosen).option1
                btnAnswerB.Text = Questions(questionChosen).option2
                btnAnswerC.Text = Questions(questionChosen).option3
                btnAnswerD.Text = Questions(questionChosen).option4
            strAnswer = Questions(questionChosen).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



I was just wondering, as I can't seem to find the answer anywhere, how can I stop the questions from possibly repeating?

Thank-you.

Is This A Good Question/Topic? 0
  • +

Replies To: How can you stop an array from repeating a question? Visual Basic 2010

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8371
  • View blog
  • Posts: 31,100
  • Joined: 12-June 08

Re: How can you stop an array from repeating a question? Visual Basic 2010

Posted 26 August 2013 - 09:32 AM

Have you array of questions.. when you randomize pick two values inside the array.. swap those positions.. do that for how ever many times.. you'll never have a duplicate question and not have more/less than you started!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1