how to make calculations with powerpoint using VBA? like a game show scoreboard

D

Derek S

so im trying to figure out how to program in powerpoint using VBA a
way to keep score based off which slide i choose to go to...for
example, "a weakest link" game board when I can "bank" the scores and
display the score. so the immediate score would reflect three buttons:
correct, incorrect, bank
correct would continue the movement up the point ladder (10, 20, 50,
100,..1000) while incorrect would return to 0. these elements can be
taken care of through slides in powerpoint, but banking the score into
your total is the tricky part as i want to bank say 500 to be
displayed along side the ladder as I continue to play and banking
again, thus keeping tally..

i have no idea where to go with this...help would be dandy. let me
know if you need better explanation.
 
B

Bill Foley

Persistent little bugger aren't ya? Two posts within 2 minutes with
different subject lines on the same topic!

Well, the good news is that I can provide some starting points to "keeping
score", but the bad news is that I haven't gotten the information in a
fully-completed FAQ yet so it will have to be via this NewsGroup.

Basically, the process consists of a few steps:

1. You need to have specific names for objects on your slides so you can
access those objects via code and tell them what their text value is. One
of our other MVPs (Shyam) has all sorts of excellent VBA samples and add-ins
that will help you when you are ready to delve into VBA. The site link is:
http://www.mvps.org/skp/index.html

The code for naming shapes is:

Sub NameShape()
Dim Name$
On Error GoTo AbortNameShape

If ActiveWindow.Selection.ShapeRange.Count = 0 Then
MsgBox "No Shapes Selected"
Exit Sub
End If
Name$ = ActiveWindow.Selection.ShapeRange(1).Name

Name$ = InputBox$("Give this shape a name", "Shape Name", Name$)

If Name$ <> "" Then
ActiveWindow.Selection.ShapeRange(1).Name = Name$
End If
Exit Sub

AbortNameShape:
MsgBox Err.Description

End Sub

2. The next thing is to create variables for the desired values you want to
maintain. If you have three players, the variables might be:

Dim intScore1 As Integer
Dim intScore2 As Integer
Dim intScore3 As Integer

3. The next thing is to have a macro that adds a value to the desired
variable. This basically takes the existing score and adds the desired
amount to it. Something like:

Sub Player1Correct100()
intScore1 = intScore1 + 100
End Sub

4. The next thing is to take that value and make it the "text" of an object
on your slide. For example I put a rectangle inside the podium for a given
player on Slide 3, run the nameshape macro and call the shape
"Player1Score". I then tell the text range of that object to be intScore1.
For example:

ActivePresentation.Slides(3).Shapes("Player1Score").TextFrame.TextRange.Text
= intScore1

5. I then put a line of code to take you back to a particular slide (if
desired). In my Jeopardy sample, I also hide the number object on the board
(set the visible property to FALSE). So, putting all that together, some
thing like this:

Dim intScore1 As Integer

Sub Player1Correct100()
intScore1 = intScore1 + 100

ActivePresentation.Slides(3).Shapes("Player1Score").TextFrame.TextRange.Text
= intScore1
ActivePresentation.Slides(4).Shapes("1-100").Visible = False
ActivePresentation.SlideShowWindow.View.GotoSlide (3)
End Sub

6. Last and most important, is to set the Action Settings of your buttons to
run the desired macro. You may have three buttons (Correct, Incorrect,
Bank) that add a value to intScore1 or even set intScore1 to zero (intScore
= 0).

If you want to check out my Jeopardy sample, go to the following link and
download it:

http://www.pttinc.com/ppgame.htm#PPGame

GOOD LUCK! Holler back if you need assistance.
 
D

David M. Marcovitz

If what Bill said makes sense to you, then you should be in good shape.
If it went over your head, you might want to check out my book:

http://www.loyola.edu/education/PowerfulPowerPoint/

The site has lots of examples and the book explains things like keeping
score at a very basic level. The specific example you want is not
included in the book, but you can get the basic idea and use Bill's
example to get the details.

--David

--
David M. Marcovitz, Ph.D.
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

Top