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
Do'stlaringiz bilan baham: