Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Contol Arrays for better option buttons

Code Links

Use Contol Arrays for better option buttons

by  MrMoocow  Posted    (Edited  )
<-Revised->
Many newbies will place multiple option buttons and write code for each one. This will explain the easiest and most effiecent way.

Step One:
Make an option but, name it and caption it as you like.

Step Two:
Right click it and select Copy

Step Three:
Right click the form or frame you want the next control to be, and select paste.

-> It will ask if you want to create a control array, Select yes.

Repeat three as many times as nessacary.

Now double click any one of those option buttons.

It should be now in the code view,

Each of those option buttons has the property index too, now heres how you set the code for each of them..

your code so far should look like this..

Private Sub Option1_Click(Index As Integer)

End Sub

now if you have two option buttons heres what it would look like...


Private Sub Option1_Click(Index As Integer)

Select Case Index
Case 0
msgbox "Option 1"

Case 1
Msgbox "Option 2"

end select

End Sub

This code cuts down on the number of subs and will speed up your programs.


www.moosoft.cjb.net
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top