Question Trying to find the right code for the score to add +1 each time correct answer given

Alaskia

New member
Joined
Feb 6, 2014
Messages
2
Location
United Kingdom
Programming Experience
Beginner
This is class work which we had to do, make up a quiz using multiple choice and single answers unfortunately I have not been able to get the score to add up, the score is stuck at 0 and it doesn't add 1 each time the correct answer is given I was wondering if you could help me out.

These 2 images are the code which i have written one for the module and one for the question I know i have left out some code but I can't figure it out.



Thank you very much. image one.jpgimage 2.jpg
 
Firstly, please don't post large screen shots just to display a few lines of code. It just makes it harder for us. If you want to post code then post code, as text, in formatting tags, e.g. this:

[xcode=vb]Dim x As Integer = 100[/xcode]

produces this:

Dim x As Integer = 100
It's easy for us to read because it's formatted and doesn't contain lots that is irrelevant and it's text so we can copy and paste it if needed.

As for your question, each time you click the Confirm Button, if both CheckBox2 and CheckBox4 are checked, it will add 1 to the Score and then close the current form. If that's what you want to happen then that code will do it. If that's not what you want to happen then you're going to have to explain exactly what it is that you do want if we are to be able to suggest how to do it in code.

By the way, if those CheckBoxes are for the user to provide an answer to a multiple choice question then you've got a problem. Presumably the user can only provide one answer but CheckBoxes are independent so they could check all of them if they wanted to. If you want to limit them to one answer from multiple then you should be using RadioButtons rather than CheckBoxes.
 
Also it looks like you have 2 variables called Score; one is a global variable initiated in the module and the second is as a private variable / property of the class. It looks like you have several forms, one for each question, and if you've set up all of those the same way, then each has its own Score variable which gets initialized each time that form opens. Hence why the Score keeps getting "reset", and if you are displaying the score in some "master" form, then it will only use its own variable, unless that form doesn't have its own member variable, in which case it'll use the one in the module, which none of the other forms would be incrementing since those forms will just use its own variable. To state which "Score" variable you mean, you should put in its scope:
Me.Score = Me.Score + 1
adds 1 to the member variable / property of the current form while
Module1.Score = Module1.Score + 1
will add 1 to the global variable defined in your module.
 
Back
Top