CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2000
    Posts
    264

    Option Button Array

    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?


  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Option Button Array

    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
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Join Date
    Jan 2000
    Posts
    264

    Re: Option Button Array

    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.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured