DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: arrays within an array?

  1. #1
    Fungus Guest

    arrays within an array?

    I have a string aray of 10 questions and want to display one at a time with
    each question having 4 possible answers and the user must choose the correct
    one (Im using 5 separate labels to display the questions and answers). This
    is like a multiple choice questionnaire prog.

    How can I best link the answers to the questions though?

    Using select case I could say if question 1 is selected then display the
    associated answers and maybe have a variable which holds the correct answer.
    But should I be trying to give each element of the question array an array
    of its own which contains the answers (if so how is that done?).

    Fred Melba



  2. #2
    Dean Earley Guest

    Re: arrays within an array?

    "Fungus" <FredMelba7@yahoo.com> wrote in message news:3d525d3b@10.1.10.29...
    > I have a string aray of 10 questions and want to display one at a time with
    > each question having 4 possible answers and the user must choose the correct
    > one (Im using 5 separate labels to display the questions and answers). This
    > is like a multiple choice questionnaire prog.
    >
    > How can I best link the answers to the questions though?
    >
    > Using select case I could say if question 1 is selected then display the
    > associated answers and maybe have a variable which holds the correct answer.
    > But should I be trying to give each element of the question array an array
    > of its own which contains the answers (if so how is that done?).


    I would do it like this

    Type Question
    QuestionText As String
    Answers(0-3) As String '0 to 3 is 4 items
    Answer As Integer
    End Type

    Dim Questions(0 to 9) As Question

    Then for the 3rd answer to Question 7, do:

    LabelAnswer(2) = Questions(6).Answers(2)

    Have fun

    --
    Dean Earley (dean.earley@icode.co.uk)
    i-Catcher Development Team

    iCode Systems



  3. #3
    Rick Rothstein Guest

    Re: arrays within an array?

    You could use a 2-dimensional array. The first dimension could represent
    the question number and the second dimension the question and its
    answers. Something like this...

    Dim MyTest(1 To 50, 0 To 4) As String
    ' First Question
    MyTest(1, 0) = "Whose your daddy?"
    ' Possible Answers To First Question
    MyTest(1, 1) = "The mailman."
    MyTest(1, 2) = "I am."
    MyTest(1, 3) = "The man your mommy married."
    MyTest(1, 4) = "Mom isn't sure."
    ' Second Question
    MyTest(2, 0) = "How many moons around earth?"
    ' Possible Answers To Second Question
    MyTest(2, 1) = "0"
    MyTest(2, 2) = "1"
    MyTest(2, 3) = "4"
    MyTest(2, 4) = "21"
    '
    ' and so on for all 50 questions the array
    ' was dimensioned for.
    '

    Of course, you would store these question in a file and read them into
    the array from there. The answers could be stored in a simple string
    variable and stored separately. Each character position would represent
    a question on the test (character position 1 would be a number from 1 to
    4 representing the answer to question 1, character position 2 would be a
    number from 1 to 4 representing the answer to question 2, and so on) and
    you would use the Mid$ function to retrieve the answer to a particular
    question. If the correct answer to the above questions were 4 and 1
    respectively, then (using dots to indicate the other characters of the
    string, up to 50 for the 50th question)

    Dim MyTestAnswers As String
    MyTestAnswers = "41...."

    Keeping the answers separate from the questions would help (no
    guarantees though) protect the test answers from anyone who looked at
    your computer's file system. Store the answers in a different directory
    with a name that doesn't have "TestAnswers" in it <g>.

    Rick


    "Fungus" <FredMelba7@yahoo.com> wrote in message
    news:3d525d3b@10.1.10.29...
    > I have a string aray of 10 questions and want to display one at a time

    with
    > each question having 4 possible answers and the user must choose the

    correct
    > one (Im using 5 separate labels to display the questions and answers).

    This
    > is like a multiple choice questionnaire prog.
    >
    > How can I best link the answers to the questions though?
    >
    > Using select case I could say if question 1 is selected then display

    the
    > associated answers and maybe have a variable which holds the correct

    answer.
    > But should I be trying to give each element of the question array an

    array
    > of its own which contains the answers (if so how is that done?).
    >
    > Fred Melba
    >
    >



  4. #4
    Fungus Guest

    Re: arrays within an array?

    Thanks both!

    Fred Melba



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center