Word Document Properties


Part III: Expanding Your VBA Horizons



Download 8,82 Mb.
Pdf ko'rish
bet162/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   158   159   160   161   162   163   164   165   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Part III: Expanding Your VBA Horizons 
14_046500 ch08.qxp 12/5/06 5:36 PM Page 192


The code uses one of two methods for displaying the message box. When you
don’t define help, it passes just the prompt, the style options, and the title to
the 
MsgBox
function. When you do define help, the code also passes the help
filename and the help context to the 
MsgBox
function.
At this point, the 
Show
method pauses. It waits for you to click one of the but-
tons on the message box. After you click one of the buttons, control returns
to the 
Show
method.
The code calls the 
RaiseEvent
method next. See the following “Defining
events” section for more information about events. In this case, the code
raises the 
Click
event to show that you’ve clicked a button. Notice that the
Click
event receives the return value from the 
MsgBox
function call. Finally,
the 
Show
method also returns the result to the caller. Using this approach
lets you react to a message box return value as either a method call return or
an event, which increases the flexibility of the 
MsgBox
function. You can also
choose to ignore the return value.
Defining events
Events are an essential part of most classes. They signify that you’ve done
something to the control. The example provides two kinds of events, but
the actual number that you can create is unlimited. Anytime that an action
occurs, you can 
fire
(raise) an event. However, most classes limit their events
to a user action or a change in data.
The example code in the preceding “Defining methods” section shows one
way to fire an event. You use the 
RaiseEvent
method to perform this task.
Before you can fire an event, you must define it. Events are always public,
but you should include the 
Public
keyword to ensure that your event works
with future versions of VBA and that you avoid making the code hard to read.
Here are some examples of event declarations:
‘ Define an event that occurs when the user clicks a
button.
Public Event Click(Result As VbMsgBoxResult)
‘ Define events for various property changes.
Public Event ChangeButton(Result As ButtonTypes)
Public Event ChangeIcon(Result As IconTypes)
The event declarations always include the 
Event
keyword and the event
name. The example uses 
Click
as an event name because that’s what other
VBA objects use for this particular event. Arguments are optional. All three of
the declarations use single arguments in this case. I prefer to include informa-
tion that I think I might need later as part of the event declaration rather than
get that information by using other means.
193

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   158   159   160   161   162   163   164   165   ...   207




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish