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


MsgBox will pop up say ing “You got a lot of questions right.” If the vari able numCorrect


Download 1.37 Mb.
Pdf ko'rish
bet115/191
Sana08.05.2023
Hajmi1.37 Mb.
#1442581
1   ...   111   112   113   114   115   116   117   118   ...   191
Bog'liq
2.2. Powerful PowerPoint For Educators

MsgBox
will pop up say ing “You got a lot of questions right.”
If the vari able
numCorrect
is not greater than 6 (it is 6 or less), then the
MsgBox
will say “You can do better than that.”
This can be extended to check more than one thing using
ElseIf
. You
might say: if it is rain ing, we will play in side; if it is snow ing, we will build
snowmen; oth erwise, we will play baseball.
If rain 
ing = True Then
PlayInside
ElseIf snow 
ing = True Then
BuildSnowmen
Else
PlayBaseball
End If
118 More Tricks for Your Scripting Bag


In this case, we ask one ques tion. If the answer is yes, we do the first thing. If the
answer is no, we ask a second ques tion. If the answer to the second ques tion is
yes, we do the second thing. If the answer to the first question is no, and the an -
swer to the second ques tion is no, we do the third thing. Note, we can ask as
many questions as we want by putt ing more and more
ElseIf
state ments. Imag-
ine a grad ing pro gram that converts num bers to letter grades:
Sub WhatsMyGrade()
If gradeNum >= 90 Then
MsgBox("You got an A")
ElseIf gradeNum >= 80 Then
MsgBox("You got a B")
ElseIf gradeNum >= 70 Then
MsgBox("You got a C")
ElseIf gradeNum >= 60 Then
MsgBox("You got a D")
Else
MsgBox("You got an F")
End If
End Sub
This assumes that a variable named
gradeNum
has been given a value some-
where else. It then asks the question, is this grade greater than or equal to 90? If
the answer is yes, it pops up a box with the message “You got an A,” and it stops.
However, if the an swer is no, it asks the next question: is this grade greater than
or equal to 80? If the answer to this ques tion is yes, it pops up a box with the mes-
sage “You got a B,” and it stops. It keeps asking questions as long as the an swers
are no. If all the answers are no, it reaches the 
Else
statement and pops up a box
with the message, “You got an F.”
Note that you can do more than one thing in re sponse to a yes an swer. You
might, for ex ample, pop up a

Download 1.37 Mb.

Do'stlaringiz bilan baham:
1   ...   111   112   113   114   115   116   117   118   ...   191




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