Radio Buttons & Check Boxes

Radio Buttons
These controls are similar in that they let the user select from a set of options. They are different in that Radio Buttons only allow one of the set to be selected at a time, while Check boxes, if used in a set, can have several in the set turned on at the same time. Selecting one Radio Button means all other buttons in the set are deselected. So Radio Buttons are used to select among mutually exclusive alternatives and are always used in sets. They appear as a circle and when selected have a dot in the circle.

On the other hand, check boxes may be used singly or in a set, and when in a set several can be selected at the same time. Check boxes are a square and when selected show a check in box. You should think of these as a push button control for turning specific features on or off. The clickable area of the buttons is larger than at first appears since you can also click on the text accompanying the buttons in order to activate the button.

The event generated when the user interacts with these controls is not a click event as it is when the user interacts with a button, but a CheckChanged event. This is because when the user clicks on these controls, they intend to change the current status of the control. A problem occurs when a beginning programmer, or one new to VB, assumes that a click means the user is selecting (turning on) that option. It is actually just as likely that the user is deselecting or turning off that option.

Think about the operation of a Check Box compared to a Radio Buttons. Check boxes have to be deselected by the program user whereas Radio Buttons are automatically deselected for the user when they click on a different radio button.

So, does clicking turn the check on or does it turn the check off? Truthfully it can do either one. If the check is currently on then clicking it will turn the check off and vica versa. This is precisely the reason why the procedure is named CheckChanged. It is changing the check from its current state to the opposite state. Radio buttons and Check boxes are controls which alter the state of something in a program. Buttons are controls which activate an event procedure. If a programmer forgets that the Radio button and Check box event is CheckChanged, their coding will generate peculiar and unreliable results. Here is a program you can download which demonstrates this behaviour.

The most important effect of this, is that when we code using these controls, we must not assume that the user event is turning the state of the control on, rather it is changing the state of the control. It might be turning the control off. The easiest way to cope with this ambiguity when coding is to always use a Forced Choice selection structure. Explicitly check the state of the control by testing the Checked property of the control. Then provide one set of commands to be executed if the control is being selected, and another set of cammands to be executed if the control is being deselected. This way we can code the event to respond appropriately whether it is turned on or whether it is turned off. Typical code would look like this:

If EmailOptIn.Checked then
    optIn = True
    optIn = False
End If

This is better code - more reliable - than using just a conditional and incorrectly assuming that the user is always turning the control on. Making assumptions about the state of controls in programming always causes problems sooner or later.



Desktop Publishing
    Start of Desktop Publishing

    iPad Opinion
    iPad Update

Organizational Behaviour
    The Short and Glorious History
    Management Essentials
    Motivation - A New Look
    Problem-Solving - Getting Things Done

    Radio Buttons & Check Boxes

Theory of Constraints
    Necessary and Sufficient