Score

Hi,

I've recently started using Visual Basic 2005 express edition, so I'm pretty new to the language and so. Though I'm getting the hang of it! But I have one question:

I'm trying to make some questions in my program, something like this:

Translate the following sentences from English to French:

Do you live in England

................................................................[textbox]

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If TextBox1.Text = "Tu es alle en Angleterre " Then

MessageBox.Show("Good!")

Else : MessageBox.Show("False!")

End If

End Sub

Then if you type it in correctly, it sais in a messagebox Good or False.

That works great, but I want more, haha!

I've made a form, with a few questions like this. All works well with the Good or False thing. I've also placed a button which says: Score.

Now I want to keep track of the score, like 5/10 questions were good, and 10/10 were false. So when you push the 'Score' button there is a messagebox which says the score... I really have no idea how to do this!

I hope you can help me with this,

Thanks, Francois



Answer this question

Score

  • KalyanPushpala

    You need to create a couple of class level variables for the form - One to handle the number of questions and the second to count the correct answers.

    These variables will be accessible to any of the methods within the form. So when you get a correct answer you simply need to increment the variable on the correct answers and for every question you will increment the questions counter.

    The general psuedocode for this is

    Public Class Form1
    Private iquestions As Integer = 0
    Private icorrect As Integer = 0

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    '//Answer Validation Logic

    iquestions = iquestions + 1
    'if answer if correct then
    icorrect = icorrect + 1
    'end if
    End Sub
    End Class

    All you need to do is code up your correct answer logic to increment the variables when you validate the question to determine if the correct answer was given.

    At any time within the form you can display the amount of questions answered and the number of correctly answered.


  • Balwant Patel

    Anyone :(
  • XNA Rockstar

    Hi,

    This is exactly what I'm looking for! Thank you very much!

     


  • JN5943

    Thought you might find this interesting:

    #1 Create a New Project
    #2 Paste the Form1.Designer code over the Form1.Designer.VB file (click Show All Files in the solution explorer and expand Form1, double click Form1.Designer.VB)
    #3 Paste the Form1.VB code over the Form1 code file page
    #4 Add a new XML document and paste QA.XML into it

    Code follows:

  • Damien Morton

    Hello,

    Looks pretty complicated! Though I'll give it a try tomorrow. Thanks


  • Score