|
-
Oct 2nd, 2003, 06:05 PM
#1
Thread Starter
Fanatic Member
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.
-
Oct 2nd, 2003, 06:31 PM
#2
So Unbanned
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.
-
Oct 2nd, 2003, 08:42 PM
#3
Thread Starter
Fanatic Member
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?
-
Oct 2nd, 2003, 09:05 PM
#4
So Unbanned
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:
Private Type tQuestion
Question as String
Choices() as String
Answer as Byte ' relate this to Choices index
'anything else?
End Type
Public cQ as tQuestion ' this could be an array of the questions
'Then simply assign those values to what you want them as
Private Function Query(Decision as Byte) As Boolean
If tQuestion.Answer = Decision Then Query = True
End Function
-
Oct 2nd, 2003, 09:20 PM
#5
Thread Starter
Fanatic Member
Hmm, I think I get it now. I could do something like this:
VB Code:
Dim CurrentQuestion(149) As tQuestion
Dim Mixed(149) As Integer
Private Type tQuestion
Question as String
Choices() as String
Answer as Byte
End Type
Public Function SetupQuestions()
Dim intFN As Integer
For intFN = 0 To 39
CurrentQuestion(intFN) = intFN
Next intFN
MixQuestions CurrentQuestion(), Mixed()
End Function
Private Function MixQuestions(ByRef CurrentQuestion() As tQuestion, ByRef intReturnArray() As Integer) As IntegerDim intExclude() As Integer
Dim intUBound, intFN, intAssigningValue, intIndex As Integer
intUBound = UBound(CurrentQuestion)
ReDim intRetVal(intUBound)
ReDim intExclude(intUBound)
For intFN = 0 To intUBound
intExclude(intFN) = -1
Next intFN
For intFN = 0 To intUBound
intAssigningValue = CurrentQuestion(intFN)
intIndex = RandomInteger(0, intUBound + 1, intExclude())
intReturnArray(intIndex) = intAssigningValue
intExclude(intFN) = intIndex
Next intFN
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.
-
Oct 2nd, 2003, 10:08 PM
#6
So Unbanned
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|