Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

incorrect answer in quiz

Status
Not open for further replies.

BallBoy

Programmer
May 6, 2003
1
US
I am having a few problems creating a simple quiz. In all my questions (3 of them), C is the correct answer. When the user answers A or B, I have a lblMsg box that should say Incorrect. When the user answers C, it should say Well Done - Click Go. The way it is right now is that it doesn't say anything after guessing A or B and when the user guesses C, it says Well Done - Click Go. Then after clicking go again, it says Incorrect. Then again after clicking go, it finally goes to the next question on the form2. Here is the code that I currently have:

Private Sub Command2_Click()

If Trim(UCase(Text1.Text)) = "C" Then
lblMsg.Caption = "Well Done"

QuestNum = QuestNum + 1
If QuestNum > UBound(Quest, 2) Then
lblMsg.Caption = "Done"
Form1.Hide
Form2.Show
End If

QuestNum = QuestNum + 1
If QuestNum > UBound(Quest, 2) Then
lblMsg.Caption = "Incorrect"
End If
End If


End Sub

Private Sub Command3_Click()
End
End Sub

Private Sub Form_Load()
ReDim Quest(4, 4)
QuestNum = 1

Quest(0, 1) = "Which President is on the One Dollar Bill?"
Quest(1, 1) = "George W. Bush"
Quest(2, 1) = "Bill Clinton"
Quest(3, 1) = "George Washington"
Quest(4, 1) = 3

Quest(0, 2) = "Which of the following basketball players plays for the Indiana Pacers?"
Quest(1, 2) = "Michael Jordan"
Quest(2, 2) = "John Stockton"
Quest(3, 2) = "Reggie Miller"
Quest(4, 2) = 3

Quest(0, 3) = "What 24 hour news network does Larry King work for?"
Quest(1, 3) = "MSNBC"
Quest(2, 3) = "Fox News"
Quest(3, 3) = "CNN"
Quest(4, 3) = 3

' Show the first Q and Ans
lblQ.Caption = Quest(0, QuestNum)
lblA1.Caption = Quest(1, QuestNum)
lblA2.Caption = Quest(2, QuestNum)
lblA3.Caption = Quest(3, QuestNum)


End Sub

 
A possible alternative would be to use a Select Case statement.

Try assign the user answer to a variable (say strAns) like
so-

strAns = Trim(UCase(Text1.Text))

(Remember to initialise this string as empty each time the checking code loops just to be sure your answers are correct)
Then, try -

Select Case strAns
Case Is = "A"
MsgBox "Nope"
Case Is = "B"
MsgBox "Nope"
Case Is = "C"
MsgBox "Yup"
Case else
MsgBox "Pick an answer"
End Select

Along with the message boxes you can code whether your user progresses onto the next question or stays at the current one here. It might be better.

Brendan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top