Results 1 to 6 of 6

Thread: Need a bit of advice about parsing questions and answers

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Need a bit of advice about parsing questions and answers

    I'm writing a trivia type game, and I would like to know what's the best way to define your questions and multiple-choice answers without having to use a long list of Select Case statements.

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Standardize the format so you can use one function for all questions(or series of functions, maybe even a class).

    I'd suggest UDTs. You don't necessarily need a Select Case structure. I don't see any problems with an If Else structure.

    You could either make an array for the questions or load them as needed, loading them as needed would be less memory consuming.

  3. #3

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    The If/Else would be a good idea, but I plan to have over 150 questions total by the time I'm through, that's why I wanted to avoid that.

    What do you mean by loading them as needed? Do you mean defining the question in code as needed?

  4. #4
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    No... I mean you're going to have to store these questions somewhere. I suppose you could do it intrinsically. But I would suggest an external file so you could supplement questions.

    Then have a UDT:

    VB Code:
    1. Private Type tQuestion
    2.  Question as String
    3.  Choices() as String
    4.  Answer as Byte ' relate this to Choices index
    5.  'anything else?
    6. End Type
    7.  
    8. Public cQ as tQuestion ' this could be an array of the questions
    9.  
    10. 'Then simply assign those values to what you want them as
    11.  
    12. Private Function Query(Decision as Byte) As Boolean
    13.  If tQuestion.Answer = Decision Then Query = True
    14. End Function

  5. #5

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    Hmm, I think I get it now. I could do something like this:


    VB Code:
    1. Dim CurrentQuestion(149) As tQuestion
    2. Dim Mixed(149) As Integer
    3.  
    4. Private Type tQuestion
    5.     Question as String
    6.     Choices() as String
    7.     Answer as Byte
    8. End Type
    9.  
    10. Public Function SetupQuestions()
    11.     Dim intFN As Integer
    12.     For intFN = 0 To 39
    13.         CurrentQuestion(intFN) = intFN
    14.     Next intFN
    15.     MixQuestions CurrentQuestion(), Mixed()
    16. End Function
    17.  
    18. Private Function MixQuestions(ByRef CurrentQuestion() As tQuestion, ByRef intReturnArray() As Integer) As IntegerDim intExclude() As Integer
    19.     Dim intUBound, intFN, intAssigningValue, intIndex As Integer
    20.     intUBound = UBound(CurrentQuestion)
    21.     ReDim intRetVal(intUBound)
    22.     ReDim intExclude(intUBound)
    23.     For intFN = 0 To intUBound
    24.         intExclude(intFN) = -1
    25.     Next intFN
    26.     For intFN = 0 To intUBound
    27.         intAssigningValue = CurrentQuestion(intFN)
    28.         intIndex = RandomInteger(0, intUBound + 1, intExclude())
    29.         intReturnArray(intIndex) = intAssigningValue
    30.         intExclude(intFN) = intIndex
    31.     Next intFN
    32. End Function

    Then I would use your Query function to check if the answer is right, and it should behave like any "normal" trivia program.

    One question comes to my mind: How do you recall the questions and answers from the file?
    Last edited by hothead; Oct 2nd, 2003 at 09:35 PM.

  6. #6
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    You can us VB's intrinisc functions that write to records, and parse themselves automatically.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width