19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

circle <strong>and</strong> the button is said to be “on.” At most one option button in a group can be on at the<br />

same time. Therefore, if one button is on <strong>and</strong> another button in the group is clicked, the first<br />

button will turn off. By convention, the names of option buttons have the prefix opt.<br />

The Value property of an option button tells if the button is on or off. The property<br />

optButton.Value<br />

is True when optButton is on <strong>and</strong> False when optButton is off. The statement<br />

optButton.Value = True<br />

turns on optButton <strong>and</strong> turns off all other buttons in its group. The statement<br />

optButton.Value = False<br />

turns off optButton <strong>and</strong> has no effect on the other buttons in its group.<br />

The Click event for an option button is triggered only when an off button is turned on.<br />

It is not triggered when an on button is clicked.<br />

EXAMPLE 3<br />

The following program tells you if an option button is on.<br />

Private Sub cmdStatus_Click()<br />

picStatus.Cls<br />

If optOpt1.Value Then<br />

picStatus.Print “Option1 is on.”<br />

ElseIf optOpt2.Value Then<br />

picStatus.Print “Option2 is on.”<br />

End If<br />

End Sub<br />

Object Property Setting<br />

frmOptions Caption Option Buttons<br />

fraOptions Caption Options<br />

optOpt1<br />

optOpt2<br />

cmdStatus Caption Determine Status<br />

picStatus<br />

Private Sub Form_Load()<br />

optOpt1.Value = False ‘Turn off optOpt1<br />

optOpt2.Value = False ‘Turn off optOpt2<br />

End Sub<br />

[Run, click on one of the option buttons, <strong>and</strong> then click the comm<strong>and</strong> button.]<br />

Nine Elementary Controls 297<br />

The text alongside an option button is specified with the Caption property. As with a<br />

comm<strong>and</strong> button <strong>and</strong> a check box, an ampers<strong>and</strong> can be used to create an access key for an<br />

option button.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!