update textbox value

S

Stephen

I'm putting together a gameshow-type powerpoint and each slide has a question
on it. as the contestants guess answers, i will click on an action button and
make their answer and the corresponding point value appear. is there a way to
have a textbox that will keep track of points and update everytime i click
the action buttons to reveal the answers?
 
D

David M. Marcovitz

This will require VBA. With VBA, it is quite possible to do it. I have
several score-keeping examples on my site. They are in the form of quizzes,
rather than gameshows, but the basic concepts should be the same.
--David
 
S

Stephen

I'm very inexperienced using VBA. I have taken a Java class (electrical
engineering) but programming is not my forte. I found on your website
examples 8-14 and 8-17 look like they might be what i'm looking for, but when
I try to run the macros it tells me macros are disabled on this presentation,
so when I view the slideshows nothing happens. How do I enable macros, and
how do I know which code I need to update the textboxes, and how do I specify
which textboxes get updated?
 
S

Stephen

I figured out how to enable the macros and how to specify which action button
runs which macro. Do I need to get the number of points for each correct
answer from the textbox its typed in as a string, then save it as a variable
thats initial value is zero? Something like this:
points1=points2=points3=points4=points5=0
UpdatePoints()
if answer1 isClicked then
points1=43
elseif answer2 isClicked then
points2=24
elseif answer3 isClicked then
points3=17
elseif answer4 isClicked then
points4=9
elseif answer5 isClicked then
points5=7
else IncorrectAnswer()

textbox.setText(points1+points2+points3+points4+points5)

then I set all 5 action buttons to run something like this?
 
D

David M. Marcovitz

OK. Let me see if I understand what you want to do. You have 5 buttons,
each worth a different point value. When a button is clicked, the total
number of points is updated and the new value is displayed in the
textbox. Is this correct?

You could get stuff from the buttons or just hard code the point values.
This can be done with one procedure, but it might be easier to have
five. You would associate each button with one of the procedures. For
example (code is untested)

Dim score as Long

Sub Add43()
score = score + 43
UpdateScoreTextBox
End Sub

Sub Add27()
score = score + 27
UpdateScoreTextBox
End Sub

'etc.

Sub UpdateScoreTextBox()
ActivePresentation.Slides(2).Shapes("ScoreBox").TextFrame _
.TextRange.Text = score
End Sub
 
S

Stephen

That's exactly what I want to do. I drew a control textbox and entered a
default value of 0 into it. I set the action button to run macro
Slide21.Add43, but when I view as slideshow and click the answer worth 43
points, the textbox doesn't update...it stays 0.
 
D

David M. Marcovitz

Ah. Control textboxes behave a little differently. You would need

NameOfTextBox.Text = score

My code was for a regular text box. I forgot to mention that the regular
text box would need to be assigned a name of "ScoreBox" for my code to
work (Example 8.7 on my site gives procedures for naming text boxes).
With a control text box, you can use the properties to name it
NameOfTextBox or just use the default TextBox1.

--David
 
S

Stephen

I deleted the control textbox and I'm using a regular textbox but it still
doesn't work. Also, why are "Slide2" and "Slide21" showing up in the Project
Explorer in Visual Basic Editor? I'm not working on those slides.
 
D

David M. Marcovitz

Have you named the regular text box that you want to use? It has to have
a correct name that matches the name used in the code.

Slide 2 and Slide 21 are showing up in the Project Explorer because you
added control items (possibly control text boxes) to those slides. The
control stuff is very useful and fine to use; it just follows a slightly
different model than the rest of the VBA object model. If you don't have
any control items on Slides 2 and 21 and no useful code in those
modules, you can safely delete those modules.

--David
 
S

Stephen

Here's the code I've got in there right now:

Sub SetScore()
score = 0
End Sub

Sub Add5()
score = score + 5
UpdateScoreTextBox
End Sub

Sub UpdateScoreTextBox()
If ActivePresentation.Slides(1).Shapes(1).Type = msoTextBox Then
ActivePresentation.Slides(1).Shapes("ScoreBox").TextFrame.TextRange.Text =
score
End If
End Sub

Sub GetObjectName()
If ActiveWindow.Selection.Type = ppSelectionShapes _
Or ActiveWindow.Selection.Type = ppSelectionText Then
If ActiveWindow.Selection.ShapeRange.Count = 1 Then
MsgBox (ActiveWindow.Selection.ShapeRange.Name)
Else
MsgBox ("You have selected more than one shape.")
End If
Else
MsgBox ("No shapes are selected.")
End If
End Sub


Sub SetObjectName()
Dim objectName As String

If ActiveWindow.Selection.Type = ppSelectionShapes _
Or ActiveWindow.Selection.Type = ppSelectionText Then
If ActiveWindow.Selection.ShapeRange.Count = 1 Then
objectName = InputBox(prompt:="Type a name for the object")
objectName = Trim(objectName)
If objectName = "" Then
MsgBox ("You did not type anything. " & _
"The name will remain " & _
ActiveWindow.Selection.ShapeRange.Name)
Else
ActiveWindow.Selection.ShapeRange.Name = objectName
End If
Else
MsgBox _
("You can not name more than one shape at a time. " _
& "Select only one shape and try again.")
End If
Else
MsgBox ("No shapes are selected.")
End If
End Sub

I'm using PP 2003 if that makes any difference. I right clicked the action
button, went to action settings and clicked run macro "Add 5" on the action
button I'm using. It's not doing anything though. Even when I type a random
number in the textbox like 7 then run the SetScore macro (which should set
the score to 0) nothing happens. What am I doing wrong?

Thanks for your help so far, its been great and I would have had no clue on
how to start this without your help. Thank you.
 
D

David M. Marcovitz

Let's see. Here is an incomplete list of the things you could be doing
wrong:

(1) You don't have a Dim statement for score listed. Make sure you have
one of those at the top of your module:

Dim score

(2) You are specificying shape 1 on slide 1. Are you sure that the score
textbox is actually shape 1 on slide 1. If it is the first shape you
added to a slide, it is likely shape 3 because the empty placeholders
count as shapes (often shapes 1 and 2).

(3) I'd have to check if your checking the shape type is written
properly because I don't know off the top of my head. You might try
eliminating the If and End If.

(4) Your didn't actually draw a text box to put the score in so not only
is it not shape 1; it doesn't exist at all.

(5) I don't think this is the case for text boxes other than
placeholders (perhaps you are using a placeholder), when you try to
change the text of a placeholder, if there is no text in there at all,
it won't show up. Try typing something in the text box and then running
your procedures.

(6) You aren't clicking on the buttons in Slide Show mode. You can't
click buttons in Normal View.

(7) You aren't clicking the buttons at all.

(8) You have some other error that I don't see in your VBA code so it is
not running at all (try Compiling your code to see if any errors come
up).

--David
 
D

David M. Marcovitz

If you still can't figure it out, watch this brief video of me creating
the thing you are trying to do. My apologies at the end of the video,
when I ran the PowerPoint show, my buttons were outside the capture area
of the screen so you couldn't see me click on the Init button and then
the Add 5 button, but that is what I did.
--David
 
S

Stephen

HAHAHAHAAAAAAAAAA IT WORKS!!!

I don't know what was changed other than watching you click yours (jing is
really cool by the way) and renaming it again. The same code I've been trying
since this morning magically works. Thank you for all your help!
 
D

David M. Marcovitz

Great. I'm glad it worked. I watched a video from Jing that someone else
posted here a few weeks ago, and I fell in love with it. To share that
video with you took me less total time that the 8 points that I typed
about what might be your problem. It literally took about 4 minutes for
the whole thing (note that the video itself is 3 minutes long so the
sharing only took me an extra minute). I think I am going to have a lot
of use for this Jing tool. This is the first time I have used it for a
real purpose.

The biggest problem that I have with Jing is that I have a giant 22"
monitor (with comparably high resolution). If I try to create a full-
screen video from that, it is hard to watch as it won't fit on most
people's screens. I have to plan a little ahead to set up the screen
capture in a smaller portion of the screen.

--David
 

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