PDA

View Full Version : VBA coding help



jess
11-26-2009, 12:36 PM
Hi

I was wondering if anyone could help me. I am trying to create a quiz in Powerpoint 2007 and i want to be able to have a running total. I have a created three macros to help keep a running total but the line of code to make it move to the next slides is not working.

The macros are below, the correct macro is on each of the correct answers and the Initalise macro is attachted to the start here button. Can anyone tell me why its not working? :dunno

Sub Initialise()
ActivePresentation.SlideShowWindow.View.Next
NumberCorrect = 0
End Sub
Sub Correct()
ActivePresentation.SlideShowWindow.View.Next
NumberCorrect = NumberCorrect + 1
End Sub
Sub Display()
MsgBox ("You got " & NumberCorrect & " questions right")
End Sub

Thank you

Jess

John Wilson
11-27-2009, 11:18 AM
First are you sure macros are running?

Second
ActivePresentation.SlideShowWindow.View.Next

Doesn't necessarily take you to the next slide. It takes you to the next bulid which may be an animation

This will take you to the next slide

i = SlideShowWindows(1).View.CurrentShowPosition + 1
If i < ActivePresentation.Slides.Count Then SlideShowWindows(1).View.GotoSlide (i)

jess
11-30-2009, 10:14 AM
Hi

Thank you for replying. The solution you provided me with is working great thank you.

However the count i have on the macros which keeps a running total on the quiz does not work and i am not sure why. Is it possible you could help me with this?

The line of code i have used to keep a running total is highlighted below:

Sub Initialise()
i = SlideShowWindows(1).View.CurrentShowPosition + 1
If i < ActivePresentation.Slides.Count Then SlideShowWindows(1).View.GotoSlide (i)

NumberCorrect = 0
End Sub
Sub Correct()
i = SlideShowWindows(1).View.CurrentShowPosition + 1
If i < ActivePresentation.Slides.Count Then SlideShowWindows(1).View.GotoSlide (i)

NumberCorrect = NumberCorrect + 1
End Sub
Sub Display()
MsgBox ("You got " & NumberCorrect & " questions right")
End Sub

Thank you

Jess

John Wilson
11-30-2009, 10:26 AM
Hi Jess

To prevent the NumberCorrect variable being reset you need to declare it outside of all subs but in the same module.

Like this

Dim NumberCorrect As Integer

Sub Initialise()
i = SlideShowWindows(1).View.CurrentShowPosition + 1
If i < ActivePresentation.Slides.Count Then SlideShowWindows(1).View.GotoSlide (i)
NumberCorrect = 0
End Sub
Sub Correct()
i = SlideShowWindows(1).View.CurrentShowPosition + 1
If i < ActivePresentation.Slides.Count Then SlideShowWindows(1).View.GotoSlide (i)
NumberCorrect = NumberCorrect + 1
End Sub
Sub Display()
MsgBox ("You got " & NumberCorrect & " questions right")
End Sub

johnwatkins3
11-15-2012, 10:17 PM
can i get a copy of your exam?