Keeping Score w/ VBA

D

Dianne Aldridge

I'm keeping score while asking a series of questions. On each slide
I've got this:

Score
Correct 0
Incorrect 0

Each '0' (which is text that I initially typed in to create the
textbox) is held in a text box that has been named 'CorrectScoreBox'
and 'IncorrectScoreBox' respectively. I am keeping score in two
variables named NumCorrect and NumIncorrect defined as integers.

After I advance each slide, I want to update the score, i.e. update the
textbox. These are the statements that I'm trying to use:

ActivePresentation.SlideShowWindow.View.Next

ActivePresentation.SlideShowWindow.View.Slide.CorrectScoreBox.TextFrame.TextRange.Text
= Str(NumCorrect)

ActivePresentation.SlideShowWindow.View.Slide.IncorrectScoreBox.TextFrame.TextRange.Text
= Str(NumIncorrect)

Even when I don't convert the integers to strings, it doesn't work.

Any ideas?
 
B

Bill Foley

Try this:

ActivePresentation.Slides(2).Shapes("CorrectScoreBox").TextFrame.TextRange.Text
= NumCorrect

(where "2" is the slide number)

--
Bill Foley, Microsoft MVP (PowerPoint)
Microsoft Office Specialist Master Instructor
www.pttinc.com
Check out PPT FAQs at: http://www.rdpslides.com/pptfaq/
"Success, something you measure when you are through succeeding."
 
D

Dianne Aldridge

Bill, that line of code worked - thanks. But it is referencing a
specific slide. Is there any way that I can reference the 'current'
slide - whichever that one is? i.e.
ActivePresentation.SlidesShowWindow.View?

Otherwise, how would I code it - set up some sort of counter to
increment the slide number? Here's a sample of my code. This code works
for all 15 questions slide. How do I make the correct score appear on
each slide without referring to each slide number specifically?

Sub RightAnswer()
NumCorrect = NumCorrect + 1

If NumCorrect = 15 Then
MsgBox ("Amazing! A Perfect Score, " & StudentName & "!")
ElseIf NumCorrect >= 10 Then
MsgBox ("Great job! Keep it up, " & StudentName & "!")
ElseIf NumCorrect >= 5 Then
MsgBox ("That's correct, " & StudentName & "!")
ElseIf NumCorrect >= 1 Then
MsgBox ("That's the right answer, " & StudentName & "!")
End If

If ActivePresentation.SlideShowWindow.View.Slide.Name =
"LastQuestion" Then
If NumCorrect >= 10 Then
Congratulations
Else
Sorry
End If
End If

ActivePresentation.SlideShowWindow.View.Next


ActivePresentation.Slides(4).Shapes("CorrectScoreBox").TextFrame.TextRange.Text
= NumCorrect
 
D

David M. Marcovitz

ActivePresentation.SlideShowWindow.View.Slide.Shapes("CorrectScoreBox").TextFrame.TextRange.Text = numCorrect

will get you the box updated on the current slide (note: that is all one
line even though the news system might break it across separate lines).

--David

David Marcovitz
Microsoft PowerPoint MVP
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
D

Dianne Aldridge

That worked great! Now, how do I reset all of the text boxes to 0 each
time the game is started? I initially thought I might need an array,
but I'm not sure; I don't need to create storage boxes, I already have
them. And I didn't think I could use GotoSlide because that would be
visible to the user. I tried a For/Next loop - here's the code, but I
can't get the slide index to increment +1 within the loop, the editor
keeps changing it to just 1.

Sub StartGame()
NumCorrect = 0
NumIncorrect = 0

ActivePresentation.SlideShowWindow.View.Slide.SlideIndex = 3
' go to first question slide

For i = 1 To 15

ActivePresentation.SlideShowWindow.View.Slide.Shapes("CorrectScoreBox").TextFrame.TextRange.Text
= "0"

ActivePresentation.SlideShowWindow.View.Slide.Shapes("IncorrectScoreBox").TextFrame.TextRange.Text
= "0"
ActivePresentation.SlideShowWindow.View.Slide.SlideIndex 1
Next i

Is there another statement I can use to go to the next slide while
executing the loop?
 
D

David M. Marcovitz

ActivePresentation.SlideShowWindow.View.Slide.Shapes("CorrectScoreBox").TextFrame.TextRange.Text
= "0"

should be:


ActivePresentation.Slides(i).Shapes("CorrectScoreBox").TextFrame.TextRange.Text = "0"

with similar changes to the other line. This will work as long as each of
those slides has a text box with the appropriate name. Get rid of the line:
ActivePresentation.SlideShowWindow.View.Slide.SlideIndex 1

--David
 
D

Dianne Aldridge

Never mind! It resets to 0 at the start of the routine and the numbers
are replaced as each question slide is presented.

Hey, I'm learning! :)
 

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

Top