Help with counting CheckBoxs

J

Jason Potter

Beklow is acopy of my code that plays a sound and
advances to another slide when to select an answer
CheckBox.

However; I need it a tally the correct and the wrong
answers.
Is there any Help?

VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Slide1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True

Private Sub CheckBox1_Click()
Dim temp As Variant

If CheckBox1.Value = True Then 'turns backcolor to
red'


With CheckBox2
.Value = False
.BackColor = &HFFFFFF
End With
With CheckBox3
.Value = False
.BackColor = &HFFFFFF
End With
With CheckBox4
.Value = False
.BackColor = &HFFFFFF
End With

MsgBox "This is the wrong Answer"
temp = sndPlaySound
("S:\Organizations\COMM\OPS\COQ\OPS\TRAINING\Admin\sounds
2\doh.wav", &H1)

With CheckBox1
.BackColor = &HFF&
End With

pause = 1 'pause time in seconds
Start = Timer 'Timer is system timer,
counts seconds from midnight
Do While Timer < (Start + pause)
DoEvents ' Yield to other processes
while waiting
Loop
Application.SlideShowWindows(1).View.Next
End If
If CheckBox1.Value = False Then 'keeps backcolor
white if not selected'
With CheckBox1
.BackColor = &HFFFFFF
End With
End If
End Sub
Private Sub CheckBox2_Click()
Dim temp As Variant

If CheckBox2.Value = True Then 'turns backcolor to
red'
With CheckBox1
.Value = False
.BackColor = &HFFFFFF
End With
With CheckBox3
.Value = False
.BackColor = &HFFFFFF
End With
With CheckBox4
.Value = False
.BackColor = &HFFFFFF
End With
MsgBox "This is the wrong Answer"
temp = sndPlaySound
("S:\Organizations\COMM\OPS\COQ\OPS\TRAINING\Admin\sounds
2\doh.wav", &H1)
With CheckBox2
.BackColor = &HFF&
End With

pause = 1 'pause time in seconds
Start = Timer 'Timer is system timer,
counts seconds from midnight
Do While Timer < (Start + pause)
DoEvents ' Yield to other processes
while waiting
Loop
Application.SlideShowWindows(1).View.Next
End If
If CheckBox2.Value = False Then 'keeps backcolor
white if not selected'
With CheckBox2
.BackColor = &HFFFFFF
End With
End If
End Sub

Private Sub CheckBox3_Click()
Dim temp As Variant

If CheckBox3.Value = True Then
With CheckBox1
.Value = False
.BackColor = &HFFFFFF
End With
With CheckBox2
.Value = False
.BackColor = &HFFFFFF
End With
With CheckBox4
.Value = False
.BackColor = &HFFFFFF
End With
MsgBox "You are Correct"
temp = sndPlaySound
("S:\Organizations\COMM\OPS\COQ\OPS\TRAINING\Admin\sounds
2\RAIN.WAV", &H1)
With CheckBox3
.BackColor = &HFF00& 'turns backcolor to
green'
End With

pause = 2 'pause time in seconds
Start = Timer 'Timer is system timer,
counts seconds from midnight
Do While Timer < (Start + pause)
DoEvents ' Yield to other processes
while waiting
Loop
Application.SlideShowWindows(1).View.Next

End If
If CheckBox3.Value = False Then 'keeps backcolor
white if not selected'
With CheckBox3
.BackColor = &HFFFFFF
End With
End If
End Sub


Private Sub CheckBox4_Click()
Dim temp As Variant

If CheckBox4.Value = True Then 'turns backcolor to
red'
With CheckBox1
.Value = False
.BackColor = &HFFFFFF
End With
With CheckBox2
.Value = False
.BackColor = &HFFFFFF
End With
With CheckBox3
.Value = False
.BackColor = &HFFFFFF
End With

MsgBox "This is the wrong Answer"
temp = sndPlaySound
("S:\Organizations\COMM\OPS\COQ\OPS\TRAINING\Admin\sounds
2\doh.wav", &H1)
With CheckBox4
.BackColor = &HFF&

pause = 1 'pause time in seconds
Start = Timer 'Timer is system timer,
counts seconds from midnight
Do While Timer < (Start + pause)
DoEvents ' Yield to other processes
while waiting
Loop
Application.SlideShowWindows(1).View.Next
End With
End If
If CheckBox4.Value = False Then 'keeps backcolor
white if not selected'
With CheckBox4
.BackColor = &HFFFFFF
End With
End If
End Sub

'Private Sub CheckBox4_Click()
'
' If CheckBox4.Value = True Then
' value.
'End Sub
 
D

David M. Marcovitz

You need one or more variables to track the right and wrong answers. At
the beginning of your module, you could put:

Dim numCorrect
Dim numIncorrect

In some procedure that gets done early, you might want to initialize the
variables to 0:

numCorrect = 0
numIncorrect = 0

They generally start out at 0, but if the presentation goes back to the
beginning for someone else to use it, they'll need to be set back to
zero.

Now, every time a correct answer is chosen (where you had the "correct"
sound playing"), you need to update numCorrect:

numCorrect = numCorrect + 1

And where wrong answers are chosen, you need to update numIncorrect:

numIncorrect = numIncorrect + 1

Finally, when you want to report the score, you could report it however
you want. For example, using a MsgBox, you might say:

MsgBox "You got " & numCorrect & " out of " & numCorrect + numIncorect

In my book, I have a lot of examples like this with different ways of
tallying and reporting the score. I don't have examples that use
checkboxes, but the idea is the same.

--David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top