Word Document Properties


Listing 8-6 Testing the New Object



Download 8,82 Mb.
Pdf ko'rish
bet168/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   164   165   166   167   168   169   170   171   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Listing 8-6
Testing the New Object
Private WithEvents MsgObj As SpecialMsg
Private Sub btnTest_Click()
‘ Instantiate the special message box.
If MsgObj Is Nothing Then
Set MsgObj = New SpecialMsg
End If
‘ Assign some property values.
MsgObj.Caption = “This is a message object.”
MsgObj.Title = “Special Message”
198
Part III: Expanding Your VBA Horizons 
14_046500 ch08.qxp 12/5/06 5:36 PM Page 198


MsgObj.Buttons = YesNoCancel
MsgObj.Icon = Question
‘ Display the message box.
MsgObj.Show
End Sub
Private Sub MsgObj_ChangeButton(Result As ButtonTypes)
‘ Show the new button type.
lblButtonType = Result
End Sub
Private Sub MsgObj_Click(Result As VbMsgBoxResult)
‘ Show the return value.
lblReturnValue = Result
End Sub
Notice that the example declares the 
MsgObj
object as 
Private WithEvents
.
The 
WithEvents
statement is important because it tells VBA that you want
the object to handle events. When you leave out this statement, the object
doesn’t respond to any events declared in the class.
The example uses a standard form with Test and Quit buttons to test the class. The
form also contains two labels for displaying output values from the class. 
The 
btnTest_Click
sub-procedure instantiates the object, performs all the
required setups, and then displays the message box by using the 
Show
method.
Changing the button type automatically generates a 
ChangeButton
event. The example handles this event by displaying the new button type
in
lblButtonType
. Like with most event handlers, the sub-procedure is 
private and uses a combination of the object name and the event, 
MsgObj_
ChangeButton
.
The example also handles the 
Click
event. The 
MsgObj_Click
sub-proce-
dure produces the same result as the output of the 
Show
method. Which tech-
nique you use in your code depends on the results that you want to achieve.
Because you can’t directly access a form by using the Macro dialog box,
you also need to create some simple code to display the form. Create a new
module for your application and create a simple 
Sub
to show the form, as
shown here:
Sub ShowMsgBox()
‘ Display the special message box.
SpecialMsgTest.Show
End Sub
199

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   164   165   166   167   168   169   170   171   ...   207




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©www.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