Word Document Properties


Listing 7-5 Making Selections with Option Buttons



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

Listing 7-5
Making Selections with Option Buttons
Private Sub btnElseIfSelect_Click()
‘ Create an output string.
Dim Output As String
Output = “The selected color is: “
‘ Determine the color value.
If obRed.Value Then
Output = Output + “Red”
ElseIf obGreen.Value Then
Output = Output + “Green”
Else
Output = Output + “Blue”
End If
‘ Add the number string.
Output = Output + vbCrLf + “The selected number is: “
‘ Determine the number value.
If obOne.Value Then
Output = Output + “One”
ElseIf obTwo.Value Then
Output = Output + “Two”
Else
Output = Output + “Three”
End If
‘ Display the result.
MsgBox Output
End Sub
169
Chapter 7: Interacting with the User
12_046500 ch07.qxp 12/5/06 5:35 PM Page 169


The code begins by determining the status of the color option buttons. It
uses the 
Value
properties to perform this task. After the code determines
the color option status, it creates that part of the 
Output
string and moves
on to the number values. The code uses the same procedure as before to
determine the number option status.
Both of these techniques display the same output. The difference between
the two techniques is where they perform their work. If you use the first 
technique, you write more code to gain a performance advantage. The
second method requires just one sub-procedure and no global variables
but can result in a performance hit.
Choosing options with list 
boxes and combo boxes
You use 
OptionButton
controls when you want to create a 
static
list — one
that doesn’t ever change. The 
ListBox
and 
ComboBox
controls help you
create 
dynamic
lists — lists that can change while the program runs or from
session to session. The list of options doesn’t have to change, but knowing
that you have the option is helpful.
Both controls require that you 
populate
(fill) them with information. The
easiest method is to use the 
AddItem
method. Use this method when you
populate the control with the same information each time that the program
starts. You can also create an array and add the array to the 
List
property.
The advantage of this second method is that you can pass different arrays to
a function or sub-procedure when the list content requirements change. (See
Chapter 9 for details on using arrays.)
You need to consider differences in these two controls when you’re designing
an application. The 
ComboBox
is smaller, but it displays only the selected
option. To see all the options, you have to click the down arrow. The 
ListBox
is a bit more accessible because it displays many (but not necessarily all of
the) options at once.
The default 
ComboBox
setting also lets the user type in a value other than
those presented. This makes the 
ComboBox
more flexible, but it also means
that you have to deal with input errors. Set the 
MatchRequired
property
to
True
if you want the 
ComboBox
to limit the input to the choices that you 
provide. A 
ListBox
always limits input to the choices that you provide, so
there’s never a chance for input that causes a program error.
The advantage of using a 
ListBox
is that you can set the 
MultiSelect
property to allow the user to make more than one choice. This feature lets
you limit the input choices while allowing multiple inputs. Use the 
Selected
170

Download 8,82 Mb.

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