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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radio button grouping

Status
Not open for further replies.

ctlin

Technical User
Apr 17, 2002
77
US
yet more questions from the VB newbie...

how do i separately group radio buttons on the same form? it seems that when i add radio buttons on one form, they all get lumped into the same "only one at a time" radio group. i would like to have several sets of buttons on a form.

also is there a way to address a group of buttons as a whole and return the name/number of the selected radio button in one call? for example, i have a grouping of radio buttons and i don't want to check each one individually within that group to see which was chosen. perhaps something like:

somevariable = radiogroup2.Selected

thanks
 
What I have done is to create a frame, and place those radio buttons that comprise the group onto the frame. You can have as many groups as you need, just put each group together on a separate frame.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
To seperate sets for your radio button, you just need to place them in frames.

From my point of view...I think the best way is to check them individualy...
 
thanks! so that's what frames do... this whole time i thought they were decorum.
 
they help you to seperate different topics within one form..
 
As to the addressing issue - I have sometimes created a radio button control array, where the grouping is the array, and of course, placed on its frame. Then the act of checking becomes an array loop, something like the following:


for i = 1 to 5
if OptButton(i).value = True then
selectedoption = i
end if
next i

work with selectedoption

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
i created a radio button control array by accident and now my buttons are named Option1(0) Option1(1) Option2(0) and Option2(1). what does this mean, how can i address a click anywhere in the button group as one event, and how can I do this on purpose in the future? thanks.
 
It means that you have 2 radio button control arrays (Option1 and Option2). Each array has two buttons elements (0 and 1) for a total of 4 radio buttons.

Are all four of these buttons in the same group, or is this two separate groups?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
the buttons are in two different frames: somehow each frame has both an option1 and option2(seems counterintuitive to me) like so:

FRAME1
Option1(0)
Option2(0)

FRAME2
Option1(1)
Option2(1)

can i reference a click within a frame to an event rather than reference each individual button click? also, now i can't compile because the

Private Sub Option1_Click()

line has something wrong with it. how do i properly refer to the groups?
 
I agree, I would have put Option1(0) and Option1(1) on one frame for the first group, and the second group on frame2 with Option2(0) and Option2(1)

I highly recommend moving the buttons around to the setup described in the previous paragraph.

As far as the compile issue, change the event handler to the following:

Private Sub Option1_Click(ButtonID as Integer)

Select Case ButtonID
case 0
' Option1(0) was the button selected
case 1
' option1(1) was the button selected
End Select

End Sub
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
thanks. final question:
how do i make the control array? say i put several buttons in a frame and now want them to be able to be referenced as in your above post.
 
the easiest way is to create the frame, and then create the first button on that frame. Then select that button with a right mouse click, choose copy. Then right click on the frame and choose paste. It will ask if you want to create the array, and you can answer yes.

If you have everything alread defined, then in design mode while looking at the form, open the properties window. From this window you can change the (Name) and Index properties. Making all the names the same will create the array, and the Index will be the subscript into the control array.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
To make a control array, cooy the first control to the Clipboard and the paste it back. VB will ask you if you want a Control Array. What happens is that each control has the same name but a different Index property. To "undo" a control array. Change the Name of each control and then make the Index Property empty. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
I should mention that every event for controls in a Control Array will have an added parameter, the Index of the control that raised the event. Note that a Control Array is an Object (sort of a protected collection) itself. It has Count, Item, LBound and Ubound properties. It is not an array of controls i.e.
Dim aryText(10) As TextBox
is not a Control Array: It is an array of controls. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top