Powerful PowerPoint for Educators: Using Visual Basic for Applications to Make PowerPoint Interactive


Dim statement (note that noth ing is between the parentheses): Dim qAnswered() As Boolean


Download 1.37 Mb.
Pdf ko'rish
bet139/191
Sana08.05.2023
Hajmi1.37 Mb.
#1442581
1   ...   135   136   137   138   139   140   141   142   ...   191
Bog'liq
2.2. Powerful PowerPoint For Educators

Dim
statement (note that noth ing is between the parentheses):
Dim qAnswered() As Boolean
136 More Tricks for Your Scripting Bag


This says that we need an ar ray
qAnswered
to hold 
Boolean
val ues, but we
don’t know how many values we’ll need to hold. When we do know how many
values, we can use the
ReDim
state ment to tell VBA.
The question is, how and when do we know how many values we need?
The answer is that we know right away, and we can tell by how many slides we
have. In our ex ample, we have five question slides, one title slide, and one re-
sults slide, for a to tal of seven slides. That is, all but two of our slides (the ti tle
slide and the re sults slide) are ques tion slides. Thus our to tal number of ques-
tions is the to tal number of slides minus two:
ActivePresentation.Slides.Count - 2
We can use this in our 
Ini 
tial 
ize
pro cedure by assigning this value to a vari-
able (we’ll use 
numQuestions
), us ing
ReDim
to tell VBA how many items we
need in
qAnswered
, and using this value in our 
For
loop to initialize each item.
Sub Ini 
tial 
ize()
Dim i As Long
Dim numQuestions As Long
numCorrect = 0
numIncorrect = 0
numQuestions = ActivePresentation.Slides.Count - 2
ReDim qAnswered(numQuestions)
For i = 1 To numQuestions
qAnswered(i) = False
Next i
End Sub
Two words of warning about 
ReDim
:
1.
Because you have al 
ready told VBA what kind of variable
numQuestions
is with the 

Download 1.37 Mb.

Do'stlaringiz bilan baham:
1   ...   135   136   137   138   139   140   141   142   ...   191




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling