Click to See Complete Forum and Search --> : Option Button Array


gknierim
March 6th, 2000, 10:13 AM
I have a set of 6 option buttons. I have made them into an array (i.e. optButton(0), optButton(1), and so on. The question I have is how do I extract the number of the option button so I can tell what option has been selected? I'm sure this is easy but I can't seem to find the right syntax. I was trying to build a Case statement depending on which option button was selected. Any ideas?

Johnny101
March 6th, 2000, 12:16 PM
you could set a trap in the click event for the option button and using the index - check the .value property to see which one was selected.

private Sub optButtons(index as Integer)
Select Case index
case 0
msgbox "First option"
case 2
msgbox "second option"
case 3
msgbox "third option"
End Select
End Sub




Of if you prefer to do it when they are about to close the form you could use something like this:

Sub GetOptions
dim i as integer

for i = 0 to ubound(optButtons)
if optButtons(i).value then
msgbox "the " & i & " option is selected"
exit for
end if
next i
End Sub




Hope this helps,
John

John Pirkey
MCSD
www.ShallowWaterSystems.com

gknierim
March 6th, 2000, 12:43 PM
When I called the first code example, I had to use the .Index property instead of the Value property. So I coded:

optButtons(optDest(Index).Index)



I could never get the value property to work right. Anyway, the above call worked. Thanks for the code.