VBA Question

D

Dianne Aldridge

I've created a simple game consisting of 19 slides:
1 title slide
1 instruction slide
15 question slides
1 sorry slide
1 congratulations/certificate slide

Everything works fine except that when I finish answering all of the
questions and go to either the sorry or congratulations slide
(depending on the score) the PP immediately attempts to go to a next
slide; there is no next slide, so I'm kicked out of the show. I've
played with this for hours, retyped the code, tried a few variations of
the code, and still cannot figure out why PP is trying to advance
slides when there is no ActivePresentation.SlideShowWindow.View.Next
line telling it to do so. Please see my code below.

Question: I call the sorry and congratulations subroutines from within
an If/Then structure. Is the code returning to that structure after it
executes the lines in the called subroutine? There is a
ActivePresentation.SlideShowWindow.View.Next statement beneath the
If/Then.

Dim StudentName As String
Dim HaveName As Boolean
Dim NumCorrect As Integer
Dim NumIncorrect As Integer
Sub StartGame()
NumCorrect = 0
NumIncorrect = 0

HaveName = False
While Not HaveName
StudentName = InputBox(prompt:="Please type your name in the
space below", Title:="Student Name")
If StudentName = "" Then
HaveName = False
Else
HaveName = True
End If
Wend

ActivePresentation.SlideShowWindow.View.GotoSlide (2)

End Sub
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.SlideShowWindow.View.Slide.Shapes("CorrectScoreBox").TextFrame.TextRange.Text
= NumCorrect

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

End Sub
Sub WrongAnswer()
NumIncorrect = NumIncorrect + 1

If NumIncorrect >= 10 Then
MsgBox ("Sorry, that's not the right answer, " & StudentName &
".")
ElseIf NumIncorrect >= 5 Then
MsgBox ("This is not the correct answer. Keep trying, " &
StudentName & ".")
ElseIf NumIncorrect >= 1 Then
MsgBox ("Oops, you missed that one, " & 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.SlideShowWindow.View.Slide.Shapes("CorrectScoreBox").TextFrame.TextRange.Text
= NumCorrect

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

End Sub
Sub Congratulations()
ActivePresentation.SlideShowWindow.View.GotoSlide (19)

ActivePresentation.SlideShowWindow.View.Slide.Shapes("CertStudentName").TextFrame.TextRange.Text
= StudentName
MsgBox ("Congratulations! Here is your certificate, " & StudentName
& ". Be sure to print it.")

End Sub
Sub Sorry()
ActivePresentation.SlideShowWindow.View.GotoSlide (18)

End Sub
Sub PrintCertificate()

ActivePresentation.Slides(19).Shapes("PrintButton").Visible = False
ActivePresentation.Slides(19).Shapes("MenuButton").Visible = False

ActivePresentation.PrintOptions.OutputType = ppPrintOutputSlides
ActivePresentation.PrintOut From:=19, To:=19
End Sub
 
B

Bill Foley

Do you by chance have an automatically timed slide transition at the end?
If so, and it is a PPS, it will close out.
 
D

David M. Marcovitz

Dianne,

You've answered your own question. A call to another procedure is just like
you have copied and pasted the lines from that procedure into your original,
so when it is done running the procedure (such as the procedure for going to
slide 18 or 19), it comes back where it left off. It left off in the middle
of an If block, so it finishes with the IF block and continues on to the next
line of code after the IF block. In your case, that is the code that takes
you to the next slide, so you are jumping to slide 18 or 19 and then
immediately jumping to the next slide (if it exists). It looks to me like the
ActivePresentation.SlideShowWindow.View.Next after your IF block needs to go,
but without looking more carefully, I can't tell if it is needed for other
reasons.

--David

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

Dianne Aldridge

Thanks, David! I fixed it! I guess I'm a little insecure in my
knowledge of VBA, because you were right - I had answered my own
question. Once I restructured my code a little and moved that
ActivePresentation.SlideShowWi­ndow.View.Next statement (I needed it,
but not where it was), everything works fine. Thank you for your
patience...... :)
 
D

David M. Marcovitz

Great. I'm glad you figured it out. I should spend more time away from
the office and let people answer more of their own questions:)
--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 

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