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


While ques - tion checks to be sure that the answer is wrong and that we have asked fewer than  three times. Sub HowManyPlanets()


Download 1.37 Mb.
Pdf ko'rish
bet119/191
Sana08.05.2023
Hajmi1.37 Mb.
#1442581
1   ...   115   116   117   118   119   120   121   122   ...   191
Bog'liq
2.2. Powerful PowerPoint For Educators

While
ques -
tion checks to be sure that the answer is wrong and that we have asked fewer than 
three times.
Sub HowManyPlanets()
Dim an 
swer As String
Dim count As In 
teger
an 
swer = ""
count = 0
While an 
swer <> "nine" And an 
swer <> "9" And an 
swer <> "Nine" _
And count < 3
an 
swer = InputBox _
("How many plan 
ets are there in our so 
lar sys 
tem?")
count = count + 1
Wend
End Sub
The variable
count
is a num ber (an
In 
te 
ger
). We started it out as 0 (
count =
0
) be cause at the be ginning, we haven’t asked at all. Then we check to see
whether the an swer is not one of the right answers (nine, 9, or Nine), and we also
check whether the count is still less than 3. If the an swer is still wrong, and the
Loop ing 121


count is still less than 3, we ask for the an swer again and add 1 to 
count
(
count
= count + 1
). Once we have asked three times, 
count
will be 3. Then, the
question in our 
While
state ment will be no be cause
count < 3
will be 
False
.
In that case, we will stop looping.
When the con ditions are complicated, we might want to do what we have
done with the 
YourName
procedure (see Chapter 5):
Sub YourName()
Dim done As Boolean
done = False
While Not done
userName = InputBox(prompt:="Type your name", _

Download 1.37 Mb.

Do'stlaringiz bilan baham:
1   ...   115   116   117   118   119   120   121   122   ...   191




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