next up previous
Next: 12. FOR/NEXT Loops Up: VisualBasic Previous: 10. OptionButtons

11.CheckBoxes

CheckBoxes are very similar to OptionButtons. They appear in the ToolBox (on the left of the VisualBasic Window), as an icon in the shape of a small white square with a cross through it.

Beginning with a blank form, insert two of these CheckBoxes 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 Check1 Then
   Print "Check1 chosen!"
End If

If Check2 Then
   Print "Check2 chosen!"
End If

End Sub

When you run this program, you should note that you can select no CheckBoxes, or one, or both! When you click on the CommandButton you will see a message on the screen telling you which (if any) of the CheckButton you selected.

As with the OptionButtons, you can change the text property of each of the CheckBoxes so that they are called something more useful than Check1, Check2 etc. You can also label each CheckBox button by entering the label into the Caption property

Here is an example programme using CheckBoxes.

CheckBoxes allow the user to select from a number of choices. The user can select from any of the CheckBoxes - so, e.g. no CheckBoxes selected, or even all selected are both valid! As with OptionButtons they are naturally useful with the If ... Then ... statements. (See [*].)


next up previous
Next: 12. FOR/NEXT Loops Up: VisualBasic Previous: 10. OptionButtons
Chris Allton 2006-10-27