hello
Am trying to make an app which has five questions with textboxes for each question for entering answers.Question one has two textboxes worthy one mark each for the correct answer and question two one textbox worth two marks for the correct answer.I want the marks got for the correct answers in all questions to be added and displyed at the end.Any help will be appreciated

Show us what you have tried so far.

If you are trying to make an app, I assume that you made a schema of how your app would look and that you at least have some code to show us or are you just one of those homework solver snatchers? Sorry, won't work over here, me and I asume others can smell homework assignments from all over the world. Sorry mate, read the rules and do what Reverend Jim has told you.

here is what i have tried

Private sub btnNEXTQ1_click(Byval sender as system.object, ByVal e As System.EventArgs) Handles btnNEXTQ1.Click
    If txtANSWERQ1a.text="39" And txtANSWERQ1b.text="45" then
        lblscore.text="2"
    elseif txtANSWERQ1a.text="39" And txtANSWERQ1b <>"45" then
        lblscore.text="1"
    elseif txtANSWERQ1a.text<>"39" And txtANSWERQ1b ="45" then
        lblscore.text="1" 
    else
        lblscore.text="0"

this is done to the other questions but i want the scores to be updated and automatically whenever the correct answer is entered into the textbox.(am a beginer)

I'm going to use shorthand to save typing. If box1 and box2 are "39" and "45" in any order you increase score by 2. If they aren't an exact match then you only have to see if either is a match. For logic like this I prefer Select/Case rather than If/ElseIf. The format is

Select Case True
    Case <condition>
    Case <condition>
End Select

with an optional Case Else if needed. I'm going to show you another shortcut. You can use the Contains method to see if an element is present in an array. You can use this on literal arrays as well as declared arrays. Thus the logic for the first part becomes

Select Case True
    Case (box1 = "39" And box2 = "45") Or (box1 = "45" And box2 = "39")
        score += 2
    Case {"39", "45"}.Contains(box1) Or {"39", "45"}.Contains(box2)
        score += 1
End Select

Although other opinions may differ, I find that clearer than

Case box1 = "39" Or box1 = "45" or box2 = "39" or box2 = "45"

It's also easier to modify if you have additional possible answers. Note that the above works correctly even if the user enters "39" (or "45") in both boxes.

thanks alot jim
your method work one the first question and the first part of the second question.My app is like when the user answers the first question,he/she needs to click on the next button inorder to go to the next question and the marks recorded.So when the users gets two marks on the first question,the the scores should be stored and added to the marka he/she will get on the next question and the same on the other questions..
What i really wanted to find out is that are there no any other codes that should be declared at the start for all textboxes so that the app can check the answers inputed in the text boxes if they are correct or wrong and then add the automatically?

I presume that each question can have one or more answers? In that case I would suggest only one textbox and the user would be expected to answer something like "39 45". You would have to parse into two strings or compare to "39 45" and "45 39". Whether or not you should do this would depend on how complex the answers are.

how can i use one textbox on all the questions because as far as am concerned sone questions require two textboxes and if at all i was to use one textbox what code should i write inorder for the textbox to check the answers and add the scores?So there is no general code that can be written for the textbox to check the answers and add them marks automatically?

I would have to see some of the questions and answers to be able to offer a more informed opinion.

ooh ok jim the questions are as follows;
1. find the exact value of
a) 23+16.1 mark
b)35+10 .1 mark
2 factorise 3x-7(2x-5) .2marks
3.expres 0.003577 in standard form correct to two significant figures. 2marks
i want the marks to be recorded and added automatically

What about setting score to 0 before a question.
After the question add the score to a totalscore.
Repeat this for every question and finally display the totalscore.

I don't see this so much as a scoring problem as it is a problem with determining if a correct answer has been given. In the case of the first two questions it is a simple comparison although I don't see why the questions cannot be split into

Evaluate 23 + 16
Evaluate 35 + 10

That way you don't have to consider 39 45 and 45 39 as both being valid answers. I'm not sure about the question factorise 3x-7(2x-5). If the question is to simplify then the answer could correctly be expressed as -11x + 35 or 35 - 11x. To my way of thinking, factorizing means taking an integer value and expressing it as a multiplication of prime factors.

As for Express 0.003577 in standard form correct to two significant figures. I have no idea what this means. Does standard form mean scientific notation? If so then there are several ways to write this that are all correct.

If each question is going to have a unique type of answer then I don't see how this is going to work.

The answers will be hard coded for validation/comparing the entered answer and a correct answer? If so,

I once created just a sample learners driving test app (its was to test if the user is ready to go take a learners exam)

I had done it this way:

Each section/question is on its own group box and when clicking next button the currently visible groupbox will be invisible or hidden and the next groupbox will be shown.

For answers the score received are assigned to a variable (e.g: Q1Score) for score received on question 1 and so on then I had a label that display the current score its update the score as you answer.

I think that's a more easy method, but someone might have a more better method.

Mr M i would like to see the codes you coded because the app you created seems similar to the one am creating.
Jim what if the answers where multiple choice like maybe the answers for the questions are as follows;
1. A
2.D
3.C
4.A
5.B
Is it possible to code so that the scores are recorded and displayed?

If your q&a is multiple choice then just display the possible answers with radio buttons. You can keep a running count either in a label or a class level variable which is copied to a label when it changes.

Yes Jim i have put the radio buttons but the problem am facing is the code to put under the label score .If you have any suggestions if the code please tell me

I'm confused now as to what problem we are trying to solve. Going by the last couple of posts you are having trouble with tracking the score. If that is the case then using radiobuttons as a working example, create a class level variable such as

Private Score As Integer = 0

Create a groupbox named gbxQuestion and put five radiobuttons in it named radA through radE. When you want to display a question, use the property gbxQuestion.Text and set the values of radA, etc. to display the possible answers. When the user cliicks on btnSubmit to submit his choice you can compare the selected radiobutton to the correct answer and update Score if the answer is correct. At that time you can copy the value of Score to a label to display the current score.

The sample could be found Click Here: as per your request.

I went to that link and it tried to install something on my computer, then it was blocked by my anti-virus. If you won't clarify or post the code here then you are out of luck. You might also check this post which may be in response to the same homework question from another user.

Ow, the site use to have ads, to download click the download, don't follow suspicious prompts, I tried to upload it here but wasn't allowed. The file is a .rar file and inside has a VS2010 project, not exe or so, just a project.

Just attach the project zip file here. If the zip is larger than 5 meg then you may have to delete the exe files before zipping.

jim let me tell you how i have made the interface.
The app is a collection of past examination questions papers and i scanned the papers.On my form i included the picturebox in which i was putting the scanned papers and the radio buttons included to the multiple choices answers accordingly e.g 1A,B.The same is done to the other questions. There is also a lblscore control for displaying the scores.All i need is the code to put under the score button so that it can be checking the answers clicked by the user and update it as the score is being displayed.I know that suggestion you gave would work but its only that i dont know how to use a groupbox.Any help will be appreciated.

Heres the sample I did. Check the attachments

The groupbox is just a container. You don't actually have to do anything with it other than put controls in it when you create the form. If you don't have any other radiobuttons on the form you don't even need the groupbox. If you have a look at the link to the other thread that I posted you will see the code that goes under the score button.

I just saw the post. I think if the OP will have more then one question and also his answers are based on radio buttons that will be a problem if the OP have more questions and not to mention the time it will take to code for displaying the relavent questions. Group boxs simplifies all that because all you have to do is show/hide only a group box instead of coding to show/hide one by one. But in this Q, I will second you on that the OP can also not use the Group box because here the OP is using TextBoxs and Labels which he can use them multiple times for different questions. But again it depends on the simplicity and the number of main Questions (Question1,2,3...).

WOW....!!!!! Your methods really helped guyz(Mr M and Jim) my app is now displaying scores.
Am also planning to add the timer to my app but i tried some researching and i found that the timer is not displayed during execution, is it true? if not then i will need some help because i want the user to be setting time when using the app.Any help will be appreciated

Ok. Firstly. The Timer(tool) is just a timer that when you add to your app its doesn't show or visible on run time, I will say its a service, and the Timer(time) that you want can be achieved in I think two or three ways depending on your plan. But that require another thread as this thread question seems to be answered as you said above.

Mark thread solve, then search first if there hasn't been any questions already answered with your timer based question, then if not or yours is different from your findings then you can start another thread.

The easiest way out here is to use an object to do all the work and then show the results at the end. What I mean by this is to use public denominators to hold and calculate your results -

Public xScore as Integer

Private sub btnNEXTQ1_click(Byval sender as system.object, ByVal e As System.EventArgs) Handles btnNEXTQ1.Click

Dim xAnswer1a As Integer, xAnswer1b As Integer

xAnswer1a = txtANSWERQ1a.text
xAnswer1b = txtANSWERQ1b.text

'Check values returned...
If xAnswer1a = 39 Then
    xScore = xScore + 1
End If

If xAnswer1b = 45 Then
    xScore = xScore + 1
End If

'This will automatically add the correct answer or xScore will stay the same.
lblscore.Text = xScore

'You can now continue with multiple questions and only update xScore all the time
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.