Ask How Many Ques tions You Want
In the above ex ample, a simple line of VBA was used to determine the
number of questions to be asked at a time. Perhaps you want the user to pick. To
do this, simply re place
numWanted = 5
with
HowMany
in the
Ini
tial
ize
pro -
cedure, and add the fol lowing
HowMany
procedure:
Sub HowMany()
done = False
While'>While Not done
numWanted = InputBox("How many ques
tions would you like?")
If numWanted >= 1 And numWanted <= 10 Then
done = True
Else
MsgBox ("Pick a num
ber from 1 to 10")
done = False
End If
Wend
End Sub
The heart of this procedure is the
InputBox
state ment. That is re ally all that is
needed. How ever, my daughter might be inclined to type a very large number
and get a lot of ques tions (so she can put off go ing to bed). The
While
sim ply
checks to make sure the num ber chosen is be tween 1 and 10 inclusive. If you
don’t care what number is cho sen, leave out the
While
loop. If you want to al-
low a dif ferent range of numbers, change the num bers in the
While
state ment.
Keep ing Score
For my daughter at the age of five, I don’t keep score, but you might want to
report a score at the end. Add
ing scorekeeping is not hard. We will need
numCorrect
and
numIncorrect
to be de clared (
Dim numCorrect
and
Dim
numIncorrect
) at the be ginning of the mod ule and in itialized in the
Ini-
tial
ize
pro ce dure (
numCorrect = 0
and
Do'stlaringiz bilan baham: |