| View previous topic :: View next topic |
| Author |
Message |
penguiness Newbie
Joined: 06 Aug 2005 Posts: 1
|
Posted: Aug 6th, 2005 01:47 AM Post subject: Trivia Game help |
|
|
I am almost finished a trivia game for a school assignment and i have two problems that i would love some help with:
1. I would like it to be able to count how many question you've gotten correct and on the last form for it to display how many there is correct
2. Also i have a question on my trivia that asks the missing word of a song and i have a textbox so that the person can type that one word as the answer, but how do you get it to be able to identify that one word and know its correct?, i've tried so many things and i have found nothing to work. My teacher doesn't know either
Please help, it would be much appreciated |
|
| Back to top |
|
feng(tree) Newbie

Joined: 05 Aug 2005 Posts: 8 Location: bathurst australia
|
Posted: Aug 6th, 2005 03:59 AM Post subject: |
|
|
i spose all you could try is an if statement.
like if the mising word was "hammer"
then you put in the IF statement that goes something like....
IF hammer
print "correct"
or something like that. sorry my visual basic is bad and i only know IF statements in c++.
research IF statements for visual basic. _________________ ""but then again, whos to say whats right and and wrong, what, with all our modern ideas, and products!!!"
an inspiring quote by Homer j Simpson |
|
| Back to top |
|
dougthomas Moderator
Joined: 27 Jul 2005 Posts: 271 Location: Essex, UK
|
Posted: Aug 6th, 2005 05:57 AM Post subject: |
|
|
Hi,
1. When you are checking the answers, add one to a count for each correct answer. Assuming the user's answer is in the variable "strAnswer" and the correct answer is in variable "strExpectedAnswer" then the following would do
If strAnswer = strExpectedAnswer then intCorrect = intCorrect + 1
Then at the end of the program you can display the value of intCorrect
e.g. Msgbox "You have got " & cstr(intCorrect) & " Answers Correct"
2. For the missing word, the user will have typed their answer into a named textbox on your form - let's assume you've called it "Text1".
When checking the answer, compare the contents of the textbox against the answer expected - let's assume the correct answer is in the variable "strMissingWord"
e.g.
If Text1.Text = strMissingWord then
.
. do whatever you do when the answer is correct
.
intCorrect = intCorrect + 1
Else
.
. do whatever you do when the answer is incorrect
.
End If
The "If" statement is very unforgiving ! the text in the text box MUST be EXACTLY the same as the text in strMissingWord for it to be correct - including Case (You may wish to look up the UCase and LCase VB functions in order to overcome this problem.) Also, you may have to worry about stripping off leading spaces, and perhaps punctuation, that the user may have typed in. (You may wish to look up the Instr, Mid and Left VB functions which will help you)
(e.g. if the answer is "tonight" and the user puts in "tonight." is it correct or incorrect ? as it stands, the If statement above, will mark it incorrect because of the full-stop at the end of the user's answer.)
Regards
Doug |
|
| Back to top |
|
vbman995 Moderator

Joined: 19 Aug 2005 Posts: 264 Location: Planet Earth
|
Posted: Aug 19th, 2005 06:46 PM Post subject: |
|
|
A way to keep track of answers if they are correct are to use variables. You can then use a variable like:
| Code: |
correct = correct + 1
|
At the end of the program put a label on the form and add the code:
| Code: |
Label1.Caption = correct
|
Don't Forget to declare the variable as Public![/b] |
|
| Back to top |
|
|