next up previous
Next: 11.CheckBoxes Up: VisualBasic Previous: 9. Declaring your Variable

10. OptionButtons

In the ToolBox (on the left of the VisualBasic Window), you will see an icon in the shape of a small, white circle with a black dot called OptionButton.

Beginning with a blank form, insert two of these OptionButton boxes onto your form. You should move them around the form so that you can see them both. Now insert a CommandButton on to this form. Double click on the CommandButton to access the program.

Enter the following code:

Private Sub Command1_Click()

If Option1 Then
   Print "Option1 chosen!"
End If

If Option2 Then
   Print "Option2 chosen!"
End If

End Sub

When you run this program, you should first select one of the two options, and then click on the CommandButton. You will see a message appear on the screen telling you which Option you selected.

There are a few things to note about OptionButtons:

Here is an example programme using OptionButtons.

OptionButtons are a way of selecting one (and only one) of a number of choices. They naturally are useful with the If ... Then ... statements. (See [*].)


next up previous
Next: 11.CheckBoxes Up: VisualBasic Previous: 9. Declaring your Variable
Chris Allton 2006-10-27