
Need Help on a school project
see modifications to code below...
Const instruction = "Type The Letter Of the Correct Response and " & _
"Click OK. Click Cancel To Skip This Question. " _
& vbCr & vbCr
Const choice = vbCr & vbCr & "A.Stop" & vbCr & _
"B. Do Not Enter" & vbCr & "C. Slippery Road"
Dim intQuesnumber As Integer
Dim strQuestion As String
Dim strCorrectAnswer As String
Dim strResponse As String
dim booPerfectScore as Boolean
frmTraffic.Hide
booPerfectScore = True ' perfect score until they make a mistake
For intQuesnumber = 1 To 3
Select Case intQuesnumber
Case Is = 1
Question = "1.Which Sign Has A Diamond Shape?" & choice
strCorrectAnswer = "C"
Case Is = 2
Question = "2.Which Sign Has An Octagonal Shape?" & choice
strCorrectAnswer = "A"
Case Is = 3
Question = "3.Which Sign Has A Round Shape?" & choice
strCorrectAnswer = "B"
End Select
strResponse = InputBox(instruction & Question, "Traffic Sign Shape Quiz")
' (ucase forces answer to uppercase, trim gets rid of leading and trailing
junk whitespace)
if ucase(trim(strResponse)) <> strCorrectAnswer then
' oops, got it wrong
booPerfectScore = false
endif
Next
if booPerfectScore then
' show the "all correct" form
else
' show the "oh dear" form
endif
********************************
Bear in mind that you will not know which question they got wrong or how many.
If you need to know this, create an array of booleans as well:
dim booCorrect(1 to maxQuestions) as boolean
then, for each question:
if *was correct answer* then
booCorrect(question#) = true
else
booCorrect(question#) = false
booPerfectScore = false ' if you leave this here, you can test
quickly to see if all were correct
' saves going though the
entire array to get a quick answer.
endif
********************************
On a side note: If it is not outside of the scope of your project, don't forget
to use VB's visual components (after all, that's what it's best at). Your
traffic question would possibly be better posed with radio buttons. For
example:
Is it illegal to run someone over?
( ) Yes
(*) No
Anyway, best of luck, hope I have answered your questions.
Regards,
Paul.