Professional Documents
Culture Documents
Objectives
Notes
OptionButtons give users an array of choices. By clicking an OptionButton, the user selects or
deselects an OptionButton. It has a black dot inside when it is selected.
OptionButtons are sometimes called radio buttons. The user can only select one button among a
set of buttons. Buttons are grouped in sets with the use of another Visual Basic control called
Frame. A Frame is a rectangular region that holds other controls and groups these into a single set.
When one button is selected in a set of option buttons, the rest are automatically deselected by
Visual Basic. Thus, OptionButtons are useful in cases like when you want the user to select a
gender (either male or female; one can never be both male and female).
OptionButtons have similar properties with that of a Label. The text that you see beside the
OptionButton is its caption property; hence, you dont have to place a Label to identify it.
Warning: When option buttons are not placed in Frames, Visual Basic assumes that the option
buttons are independent of each other. Thus, the user can select any of them at the same
time (in our example above, the user can be both male and female).
Option Button
Frame
How do you know if an OptionButton is selected? Each OptionButton has a Value property that
contains either True or False. When the value of this property is True, the button is currently
selected. Otherwise, it is deselected.
Lesson in Action
optBlue
optRed
vbRed and vbBlue are color named literals. Since hex color formats are difficult to remember, VB
provides you with these values that represent hex values of commonly used colors. The other
colors aside from vbBlue and vbRed are as follows:
Literal
vbBlack
VbGreen
VbYellow
VbMagenta
VbCyan
VbWHite
Color
Black
Green
Yellow
Magent
a
Cyan
White
On your Own
Instructions: Create a short math drill. The drill contains 3 items. When the user presses a
button labeled Check Score, a Message Box appears revealing the his score (e.g. You correctly
answered 2 items!). The following is how the Form should look like.