Dim
state ments and
Ini
tial
ize
pro cedure from above and the
GetStarted
,
YourName
,
DoingWell
, and
DoingPoorly
pro ce dures from
any of the earlier examples, we can use the following
RightAnswer
pro ce dure
and
WrongAnswer
procedure to re place all the specialized
RightAnswer
and
WrongAnswer
pro cedures. The only thing you ever have to change is the num-
ber
5
in the
Dim
state ment and the
Ini
tial
ize
pro cedure. Just make this num-
ber equal to the num ber of questions you have.
Sub RightAnswer()
Dim thisQuestionNum As Long
thisQuestionNum = _
ActivePresentation.SlideShowWindow.View.Slide.SlideIndex - 1
If qAnswered(thisQuestionNum) = False Then
numCorrect = numCorrect + 1
End If
qAnswered(thisQuestionNum) = True
DoingWell
End Sub
Sub WrongAnswer()
Dim thisQuestionNum As Long
thisQuestionNum = _
ActivePresentation.SlideShowWindow.View.Slide.SlideIndex - 1
If qAnswered(thisQuestionNum) = False Then
numIncorrect = numIncorrect + 1
End If
qAnswered(thisQuestionNum) = True
DoingPoorly
End Sub
I Don’t Know How Many Questions:
ReDim
to the Rescue
It is very nice to cut down on the amount of VBA code that needs to be
changed, but would n’t it be nice to have the above pro cedures work without
changing any VBA code? The prob lem is that we need to know how many ques-
tions we have so we can declare and ini tialize our
qAnswered
ar ray. VBA is
very nice about this; if you don’t know how many items you need in an ar ray, it
lets you tell it whenever you know. We can declare the ar ray with the fol lowing
Do'stlaringiz bilan baham: |