Welcome to Dream.In.Code
Become a VB Expert!

Join 149,946 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,408 people online right now. Registration is fast and FREE... Join Now!




Another database problem

 
Reply to this topicStart new topic

Another database problem

GrahamPaul
18 Dec, 2007 - 09:28 AM
Post #1

New D.I.C Head
*

Joined: 9 Dec, 2007
Posts: 9


My Contributions
Hi, I have made a multiple choice quiz which brings up a question and four possible answers. These are all displayed in labels and when you click non the label which you think contains the correct answer, the program will confirm your choice or tell you that your are incorrect. The problem I have is that when I click on the labels, nothing happens. See my code attached:

Many thanks...

CODE

Option Explicit
Option Base 1

Dim QuestionDB As DAO.Database
Dim QuestionTable As DAO.Database
Dim Theory As DAO.Recordset
Dim questionnumber As Integer
Dim filename As String
Dim UserAnswer As String
Dim RealAnswer As String
Dim Chosen As String



Private Sub cmdHelp_Click()

Load frmHelpQuestions
frmHelpQuestions.Show
frmQuestion.Hide

End Sub

Private Sub Form_Load()

filename = "E:\Advanced Higher Computing\Project\Program\Questions.mdb"
Set QuestionDB = DAO.OpenDatabase(filename)
Set Theory = QuestionDB.OpenRecordset("QuestionTable", dbOpenDynaset)
Datafill

If UserAnswer = RealAnswer Then
MsgBox ("Well done! That is correct.")
Theory.MoveNext
End If

If questionnumber = 16 Then
Load frmResults
frmResults.Show
frmQuestion.Hide
End If

End Sub

Public Sub Datafill()

If questionnumber <= 15 Then
lblHeading.Caption = "Question " & questionnumber & " out of 15"
LabelQuestion.Caption = Theory!Question
Label1.Caption = Theory!A
Label2.Caption = Theory!B
Label3.Caption = Theory!C
Label4.Caption = Theory!D
RealAnswer = Theory!Answer
End If


End Sub
Private Sub Label1_Click()
UserAnswer = "A"
End Sub


Private Sub Label2_Click()
UserAnswer = "B"
End Sub


Private Sub Label3_Click()
UserAnswer = "C"
End Sub


Private Sub Label4_Click()
UserAnswer = "D"
End Sub




Private Sub lblExit_Click()
End
End Sub

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Another Database Problem
18 Dec, 2007 - 11:30 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Well that is because all you are doing in the label click events is assign a value to your variable. You will need to set the variable like you are and then do something to show the answer to the user. For instance...

CODE

Private Sub Label1_Click()
    UserAnswer = "A"

    ' If the answer they chose is the same as the real answer, tell them so.
    ' Otherwise tell them they are wrong and do something else to show them that they are wrong.
    if UserAnswer = RealAnswer then
        MsgBox("The answer is correct! Good Job!")
    else
        MsgBox("Sorry, your answer was incorrect. The real answer is: " & RealAnswer)
    end if

End Sub



You are just missing any code that tells the program what to do after they select their answer. In the code above we are telling it to set their answer and then compare it against the real answer and show a message if it is wrong or right.

That is all there is to it. You just need to continue along with the logic in each event.

Hope that helps!

"At DIC we be quiz question checking code ninjas!" decap.gif

User is offlineProfile CardPM
+Quote Post

GrahamPaul
RE: Another Database Problem
19 Dec, 2007 - 12:31 PM
Post #3

New D.I.C Head
*

Joined: 9 Dec, 2007
Posts: 9


My Contributions
Thanks a lot, I have it working.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 05:05PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month