OptionButton and Frame Controls


Have a look at some interesting features of the OptionButton and Frame controls in Visual Basic 6. I'm discussing the frame control with option button in this lesson, because the Frame control is often used with option buttons when you want to have a couple of groups of the option button controls. 

Note that in the higher versions of Visual Basic and in some other languages, the term Radio Button is used instead of Option Button for the same control.




The OptionButton Control

This control lets you choose from several items among other in a list. This is one of the mostly frequently used controls in application developement. When you click on an OptionButton, it is switched to selected state or ON state, and all other option buttons in the group become unselected or OFF.

Example:

Private Sub Command1_Click()
    If Option1.Value = True Then
        Print "Option1 is ON"
    Else
        Print "Option1 is OFF"
    End If
End Sub

Output:

Simple option button program


When Option1.value = True  then the Option Button is ON and when Option1.value = False then the Option button is OFF. 



Example:
Private Sub cmdCheck_Click()
    If optWindows.Value = True Then
        Print "Windows is selected"
    ElseIf optLinux.Value = True Then
        Print "Linux is selected"
    ElseIf optMac.Value = True Then
        Print "Mac is selected"
    End If
End Sub

Output:

Example program with three option buttons



See the following page for the above program's code and exaplanation:

 

Frame 

Frame is a container control as the Frame control is used as a container of other controls. The controls that are on the frame or contained in the frame are said to be the child controls. Use the Caption property to set the frame's title.

One of the most useful features of the Frame control is that when you move the frame, all the child controls also go with it. If you make the frame disabled or invisible, all the child controls also become disabled or invisible.

This container control is often used when you wish to select more than one OptionButton controls which are separated in a couple of groups like in the following sample program. 
  • Get the above program explained here: Samples.