Word Document Properties


Chapter 7: Interacting with the User



Download 8,82 Mb.
Pdf ko'rish
bet145/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   141   142   143   144   145   146   147   148   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Chapter 7: Interacting with the User
12_046500 ch07.qxp 12/5/06 5:35 PM Page 167


be a source of errors. Listing 7-4 shows an example of using the global variable
approach. (You can find the source code for this example on the Dummies.com
site at 
http://www.dummies.com/go/vbafd5e
.)
Listing 7-4
Using Global Variables with Option Buttons
Private ColorSelect As String
Private NumberSelect As String
Private Sub btnStatus_Click()
‘ Create an output string.
Dim Output As String
Output = “The selected color is: “ + ColorSelect + _
vbCrLf + _
“The selected number is: “ + NumberSelect
‘ Display the result.
MsgBox Output
End Sub
Private Sub obBlue_Click()
‘ Change the ColorSelect value.
ColorSelect = obBlue.Caption
End Sub
Private Sub obGreen_Click()
‘ Change the ColorSelect value.
ColorSelect = obGreen.Caption
End Sub
Private Sub obOne_Click()
‘ Change the NumberSelect value.
NumberSelect = obOne.Caption
End Sub
Private Sub obRed_Click()
‘ Change the ColorSelect value.
ColorSelect = obRed.Caption
End Sub
Private Sub obThree_Click()
‘ Change the NumberSelect value.
NumberSelect = obThree.Caption
End Sub
Private Sub obTwo_Click()
‘ Change the NumberSelect value.
NumberSelect = obTwo.Caption
End Sub
Private Sub UserForm_Initialize()
168
Part II: Learning the Ropes 
12_046500 ch07.qxp 12/5/06 5:35 PM Page 168


‘Set the initial global values.
ColorSelect = obRed.Caption
NumberSelect = obOne.Caption
End Sub
Using global variables means that you have to set them to some initial value.
The 
UserForm_Initialize
sub-procedure performs this task when you
start the program. When you click each 
OptionButton
control, VBA calls
the appropriate 
Click
event handler. The event handler changes one of the
two global variables, 
ColorSelect
or 
NumberSelect
, as appropriate. Click
the Status button, and VBA calls the 
btnStatus_Click
sub-procedure. Notice
that this sub-procedure has little work to do because the program tracks the
option button status.
Another approach is to use a series of 
If...Then...ElseIf
statements to
determine which 
OptionButton
control is selected by using the 
Value
property. Listing 7-5 shows a sample of the selection process that uses this
second method.

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   141   142   143   144   145   146   147   148   ...   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