Thursday, May 28, 2009

VB-Day Six (6) Option Button

in most of the softwares when you are given a few options and you are supposed to select at most one of these options then Option button is the best option to use. for example your country of birth. if you are given hundereds of country names and said that please select your country of birth then it will be only one you can select so option buttons form a group and from that group you can select only one option.

another example of the use of option button is selection of Gender. either Male or Female

its default name is option1, option2 and so on.

another property is Caption that is used to display what text you want to associate with it. you can have more than one groups by using Frame Object i.e on one form all option buttons will be treated as of one group so if you need some more groups then use Frame and drag option buttons on frame. each frame is a seperate group.

and to use it in code just use it as
suppose i have two option buttons named OpMale and OpFemale and i want to check whether the user selected Male of Female. i have another command button and a Label Named Lbl1

on click event of command button

'----------------------------------------------------
Private sub Command1_Click()

if OpMale.Value=True then
Lbl1.Caption="You have selected Male"
elseif OpFemale.Value=True then
Lbl1.Caption="You have selected Female"
end if

End Sub
'--------------------------------------------------

similary you can check which option button is selected. also the above functionality can be attained by coding directly on

1 comment:

  1. what if i want to select more than one options on a single form?

    ReplyDelete