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


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

While StillRaining
AddBlockToTower
Wend
PlayOutside()
120 More Tricks for Your Scripting Bag


In this case, the ques tion is: Is it still rain ing? If the an swer is yes, add an other
block to the tower. The
Wend
state ment stands for While END and sim ply lim its
the loop. What ever is between the
While
and 
Wend
statements will hap pen over
and over again un til the an swer to the ques tion is no. Many things can hap pen
be tween a
While
and 
Wend
; it is not lim ited to one state ment. This loop will
keep executing as long as it is still raining. Once it stops, the an swer to the ques -
tion will be no, and whatever is after the
Wend
will be ex ecuted. In this case, my
daughter will fi nally go play outside.
We could use this to ask a ques tion un til the right answer is entered. For
ex am ple:
Sub HowManyPlanets()
Dim an 
swer As String
an 
swer = ""
While an 
swer <> "nine" And an 
swer <> "9" And an 
swer <> "Nine"
an 
swer = InputBox _
("How many plan 
ets are there in our so 
lar sys 
tem?")
Wend
End Sub
In this ex ample, the pro cedure
HowManyPlanets
con tains a 
While
loop with a
slightly complicated question. The ques tion ba sically asks: Is the answer wrong?
That is, is whatever the user typed not “nine,” “9,” or “Nine”? If it is not any of
those, it will ask for the an swer again and again and again un til one of those an -
swers is entered in the
InputBox
.
Sometimes we might not want our us ers to get stuck in a loop if they re ally
don’t know the an swer. We might want to limit the number of times we ask the
question. In this example, the user will be asked three times, so our

Download 1.37 Mb.

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




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