MsgBox
re turns
vbYes
. We might want to do something based on the
button pressed. For example:
'Ask if you like choc
olate. Give an ap
propriate re
sponse.
Sub Choc
o
late()
Dim chocolateAnswer
chocolateAnswer = MsgBox("Do you like choc
olate?", vbYesNo)
If chocolateAnswer = vbYes Then 'The user likes choc
olate.
MsgBox ("I like choc
olate, too.")
Else 'The user does not like choc
olate.
MsgBox ("Va
nilla is a good choice.")
End If
End Sub
Here is an ex ample for a commonly used feature: a quit button. Sometimes
users ac cidentally choose quit (by clicking on a but ton that calls a pro cedure
with
ActivePresentation.SlideShowWindow.View.Exit
). To prevent
quitting your presentation by accident, you might want to ask if the user re ally
wants to quit. As sociate the following pro cedure with your quit but ton:
The Se crets of the
MsgBox 67
'Ask if you are sure you want to quit. If the an
swer is Yes,
'exit the pre
sentation. If the an
swer is No, go to the next slide.
Sub QuitOK()
're
sult is a vari
able to keep track of which but
ton is clicked.
Dim re
sult
'MsgBox re
turns (will set the vari
able re
sult to) vbYes if the
'Yes but
ton is clicked and vbNo if the No but
ton is clicked.
re
sult = MsgBox("Are you sure you want to quit", vbYesNo)
Do'stlaringiz bilan baham: |