Need VBA help

D

Dianne Aldridge

I'm working on a series of interactive PP lessons for an action
research project that I implement next week and am having a little
trouble with the code. I typically go to Dr. Marcovitz for help, but
he's really busy this week and so I need to find an online forum. Can
we submit VBA questions here? I looked through the list of Microsoft
groups and it appears that none are devoted to VBA, and specifically
VBA for PowerPoint.

Any suggestions would be appreciated.
 
B

Bill Foley

This is the place. Ask away! I'll be sure to call Shyam, Steve, Brian,
Bill D., and others to help you! HA!
 
D

David M. Marcovitz

Dianne,

You have found the right place. I'm sure the other VBA gurus will be able
to help you if you post questions here while I am out of the office for
the next week or so.

--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/
 
D

Dianne Aldridge

Thank you, Bill! By the way, Shyam HAS been helpful in the past. :)

These are simple questions, but oh so important to me. First question:

I'm using the following IF block and for some reason it is being
ignored when I press a wrong or right answer button on a slide. A
message box never appears with either a right or wrong answer. The
slides are linked to the proper macros and the variables have been
initialized correctly. I'm pretty sure the first statement of the
nested IF below the IF block is incorrect as well. I'm trying to
determine whether or not the current slide is a slide I've named
"LastQuestion"; if it is the last question, then I want to determine
the number of correct answers; if > 10 then on to a certificate slide,
if less then to a sorry slide.

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 = LastQuestion Then
If NumCorrect >= 10 Then
Congratulations
Else
Sorry
End If
End If

ActivePresentation.SlideShowWindow.View.Next

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 = LastQuestion Then
If NumCorrect >= 10 Then
Congratulations
Else
Sorry
End If
End If

ActivePresentation.SlideShowWindow.View.Next

End Sub
 
D

Dianne Aldridge

David, you're the best! Although Bill is starting to sound pretty nice,
too............... :)

We progressive teachers really thank ALL of you for your help.
Collaboration is a beautiful thing.
 
D

David M. Marcovitz

If ActivePresentation.SlideShowWindow.View = LastQuestion Then

If ActivePresentation.SlideShowWindow.View.Slide.Name _
= "LastQuestion" Then

This should help. I'm just taking a break from reading these technology
standards that ask Pre-K kids to "Explain connectivity," use
spreadsheets, and use the Web. Now back to your regularly scheduled
helpers: Bill, Shyam, Steve, et. al. By the way, if Shyam responds, ask
him when he is going to write his PowerPoint VBA book.

--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/
 
B

Bill Foley

The first part is a little confusing to me. Is it safe to assume that this
is Question #15? Is it possible to provide a little more info on what you
are trying to accomplish with that code. Based on the various MsgBox
strings, how can a correct answer provide positive message boxes regardless
if NumCorrect is 15, 10, 5, or 1. That is the part I need a little more
info on.

As far as the second part goes, try this:

If ActivePresentation.SlideShowWindow.View.Slide.Name = "LastQuestion" Then
 
D

Dianne Aldridge

Bill,
I have 15 question slides and was wanting to provide different feedback
at different intervals of questioning. I am beginning at question 1,
slide 3. When I did my other PP lessons, I had a different Sub routine
for each quiz question, but there was only five questions, so it was no
big deal. With 15, I thought it would be more streamlined to use the
the block IF example that I obtained from David's book (p. 125;
entitled 'Parameters'). Perhaps I'm using this feature incorrectly. For
example, David's example show that the last Else statement does not
have an 'IF', appearing like:

If Then
ElseIf
ElseIf
Else
End If

But I received an error when I did not include the 'If' after the Else.


But I think you're right, there appears to be a logical error that was
obvious to me: two conditions in the block can be correct
simultaneously. The NumCorrect or NumIncorrect can be > 1 and > 5 and >
10 at the same time. Perhaps I'm not applying parameters as David is
discussing in this section of the book. Should I use a different
method?

Here's my full code at this point:

Dim StudentName As String
Dim HaveName As Boolean
Dim NumCorrect As Integer
Dim NumIncorrect As Integer
Dim printableSlideNum As Long

Sub StartGame()

MakeVisible

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

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

End Sub
 
B

Bill Foley

Here is where logic is your friend. What do you think would happen if
NumCorrect was = 15? Wouldn't that make every condition correct? VBA
doesn't like that. Try working it the other way - <=1, <5, <10, =15 and see
if that works. An If...Then...Else needs to only meet one condition and the
way yours is written every one could be correct if = 15; most correct if
between 10 and 14, etc.

Hope that helps.
 
D

David M. Marcovitz

I'm trying not to jump in here because I am about to leave for class and
be gone for about a week, but ...

In an If block, many many conditions can be true. It goes down the list
in order. If the first one is true, it does that stuff and stops. If the
first one is not true, it goes to the second one (the first ElseIf). If
that is true, it does that one and stops, and so on and so on. If none of
the conditions is true, it looks for an Else at the end and does that. In
a single, non-nested IF block, it will never execute the stuff after more
than one If or ElseIf because it stops as soon as it is gets to one If or
ElseIf section that works.

--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/
 
D

Dianne Aldridge

Bill,
Got it working. I simply retyped the code and it worked. The IF block
worked as is after I retyped it. You know how stuff can get glitched up
as you play with it. :)

Should I start a new thread for my next question?
 
B

Bill Foley

Well, the good news is I too am going to be gone for a week. The bad news
is, I might have to hit the Cap'n Morgan before the Church Softball League
tonight! HA! I keep trying to use "OrElse" in my code!

--
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."
 

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