MsgBox
has to come af ter the procedure’s
Dim
state ments). It could be that
you linked your but ton to the wrong pro cedure or, in a more complicated script,
it could be that the problem is in another procedure that calls this one. If you get
the message, you know you have got ten into the pro cedure. Now, you can add
some more
MsgBox
com mands to try to locate the problem. For example:
Sub AddStar()
Dim myShape As Shape
MsgBox ("En
tering the pro
cedure AddStar.")
Set myShape = _
ActivePresentation.SlideShowWindow.View.Slide.Shapes.AddShape _
(msoShape16pointStar, 100, 100, 100, 100)
MsgBox ("I just added the shape, and I’m about to add some text.")
myShape.TextFrame.TextRange.Text = "Good job!"
MsgBox ("I just added some text, and I’m about to change the color.")
mShape.Fill.ForeColor.RGB = vbBlue
MsgBox ("Color is changed; now I’ll change the size.")
myShape.Height = 200
myShape.Width = 200
MsgBox ("I am about to leave AddStar.")
End Sub
Try run ning the above pro cedure. See if you can find the er ror. As you run
the pro cedure, you should get the messages:
• En ter ing the pro ce dure AddStar.
• I just added the shape, and I’m about to add some text.
• I just added some text, and I’m about to change the color.
But that will be it. You will know that the prob lem is prob ably in the fol -
lowing line. If you look closely, you will see that the line has a small typo; it uses
mShape
in stead of
myShape
. Once the prob lem is fixed, try it out again. If it
works, you can de lete all the
MsgBox
lines.
You can also use a
MsgBox
to tell you what is in a variable. For example,
if something is wrong with the scoring in a quiz, you might want to use the fol-
lowing line at various places to get up dates about what the computer thinks the
score is:
Do'stlaringiz bilan baham: |