hey, i have project in my visual basic laboratory, but i'm just a newbie, so can anybody help me.. they say that its just a simple syntax, but it is not simple for me.. so please help me.. it goes like this, a quiz that has a radio button choices, using 5 forms with 10 questions each.. and at the end it must count the correct and the incorrect..

ive made this code, but i dont know what to do next.. help me please..

Private Sub Command1_Click()
If Option1.Value = True Then
Text1.Text = Val(Text1.Text) + 1
Form2.Show
End If
If Option2.Value = True Then

End If
If Option3.Value = True Then
Form2.Show
End If
If Option4.Value = True Then
Form2.Show
End If

End Sub

the number of correct answers must appear in the textbox.

Recommended Answers

All 18 Replies

Hi,

Keep a Public Variable To Count the corrct Answers In the beginnig, make Value of that variable =0.
And In all the forms add a Command button to goto next page/Form.
and in command button write the code to check if the selected option in that form is correct, then add 1 to variable and at the end, add one more form, to display the Results of the public variable..

Regards
Veena

If I understand you correctly...

It looks like you need to store two variables (for the correct and incorrect answers), have the user answer the questions, hide the first form, show the second form and carry the two variables over to that 2nd form (3rd then 4th then 5th form) so that you can accumulate a total (of correct and incorrect answers.)

i understand both of ur explanation.. but the problem is, i dont know the exact code for that kind of statement.. how can i count and produce the number of correct answers? thnks for ur time..

The following is some rough code to get you started. It assumes you have a total of 2 forms, 3 frames, 6 option buttons and two command buttons.

'This is for Form 1...

Public a as integer
public b as integer

Private Sub Command1_Click()

'Question 1.
If Option1.Value = True Then
a = 1
ElseIf Option2.Value = True Then
b = 1
End If

'Question 2.
If Option3.Value = True Then
a = a + 1
ElseIf Option4.Value = True Then
b = b + 1
End If

'Hide form 1.
Form1.Hide

'Show form 2.
Form2.Show

End Sub

Private Sub Form_Load()
a = 0
b = 0

End Sub

'This is for Form 2...

Private Sub Command1_Click()

c = Form1.a
d = Form1.b

'Question 1.
If Option1.Value = True Then
c = c + 1
ElseIf Option2.Value = True Then
d = d + 1
End If

MsgBox c
MsgBox d

End Sub

i understand.. i'll try it first.. thanks a lot bro.

bro, i converted ur syntax into the one im doing and it work.. but how if i will create another form? should i declare another variable? can you please show me the code.. thanks, u really help alot..

You create the two forms at design time. Look for a toolbar shorcut icon (that looks like a form.) Or if you can't find it, look for "Add Form" (or something like that depending on what version of vb you are using) in the menu bar. After you've created them you should be able to see (and click on/access) either of the two forms in the Project Explorer window.

You only need to declare two public variables... Variable a (which can store the number of correct answers) and variable b (which can store the number of incorrect answers.)

Hope that helps :)

i've connected the form1 and form2, but i want to create additional form. should i do this code?
but this code for the form3 is incorrect.

Private Sub Command1_Click()
e = form2.c
f = form2.d

'Question 1.
If Option1.Value = True Then
e = e + 1
ElseIf Option2.Value = True Then
f = f + 1
End If


MsgBox e
MsgBox f

End Sub

Unless I misunderstand you, I believe you have to create the 5 forms when you are initially creating your vb project (i.e at "design time.") Then you can access those forms with the code you write.

im sorry, but i dont understand what you mean..
i've already created 3 forms, and the msgbox of
the form 3 pop-ups, but it displays an incorrect value of correct and incorrect answers.
heres the code i used.

Private Sub Command1_Click()
e = Form1.a
f = Form1.b

'Question 1.
If Option1.Value = True Then
e = e + 1
ElseIf Option2.Value = True Then
f = f + 1
End If


MsgBox e
MsgBox f

End Sub

I'll post you something (a project.)

sure thanks alot.. thanks for your time again..
if i have any questions can i still ask you? if its ok..

Here you go, it's rough, but I'm sure it will do. If you want to ask questions about the project I just sent you, feel free. Don't forget, there are other people on this forum who have much more knowledge about vb than I do :)

ok.. thank you so much.. i guess that would help a lot.. are you filipino?

I just re-read this thread. It looks like I did misunderstand you. My apologies. In the second form, I declared another two public variables (c and d.) These two variables carry the two "running totals" over to the third form and thus you are able to create the total number of correct and incorrect answers. There may be a better way to do this, but it appears to work. Maybe someone can come up with a more effective solution. I've got to go (to bed!) Good luck.

In the project I uploaded it looks like you can get rid of the following code...

a = c
b = d

I'm an Aussie.

I'll try to help you, if you elaborate more. I'm not clear about what you're asking

really, but it worked.. it correctly counts the number of incorrect and correct answers.. thanks alot again bro.:) you really helped me alot.. i'll still ask you next time..:)

Glad to hear you got it working. Good work! See you later :)

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.