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


Download 1.37 Mb.
Pdf ko'rish
bet136/191
Sana08.05.2023
Hajmi1.37 Mb.
#1442581
1   ...   132   133   134   135   136   137   138   139   ...   191
Bog'liq
2.2. Powerful PowerPoint For Educators

q1Answered
and 
q2Answered
to store the
information about whether question 1 was an swered and whether question 2 was
answered. If we had more questions, we would add more variables. This is easy
to un derstand but dif ficult to type, particularly if we have a lot of questions. This
could be simplified with an array.
134 More Tricks for Your Scripting Bag


The first step is to de clare the ar ray. Suppose we have five questions. With -
out an array we would do the following to de clare our five variables:
Dim q1Answered As Boolean
Dim q2Answered As Boolean
Dim q3Answered As Boolean
Dim q4Answered As Boolean
Dim q5Answered As Boolean
If we were to use an array, we would have one line:
Dim qAnswered(5) As Boolean
This will give us an array that con tains six boxes, numbered 0 through 5:
qAnswered(0)
,
qAnswered(1)
,
qAnswered(2)
,
qAnswered(3)
,
qAnswered(4)
, and 
qAnswered(5)
. Note that we really only need five
boxes in our ex ample, and we got six. There are many ways to avoid getting the
extra box, but un less you are an aspiring pro grammer, the easiest thing to do is
simply ig nore box number 0.
Now, we can shorten our 
Ini 
tial 
ize
pro cedure. It won’t be shorter with
two questions (or sig nificantly shorter with five), but when you create some-
thing with ten or twenty questions it will be much shorter:
Sub Ini 
tial 
ize()
Dim i As Long
numCorrect = 0
numIncorrect = 0
For i = 1 to 5
qAnswered(i) = False
Next i

Download 1.37 Mb.

Do'stlaringiz bilan baham:
1   ...   132   133   134   135   136   137   138   139   ...   191




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