Results 1 to 4 of 4

Thread: [RESOLVED] Option Button --Simple question

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    13

    Resolved [RESOLVED] Option Button --Simple question

    I have an option button array. How do I return the number of the option that is selected. I'm thinking something like:
    HTML Code:
    whatever = Option1.number
    Please forgive my ignorance... I'm teaching myself how to program and have had no formal training.
    Thanks.
    Sincerely,
    J

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Option Button --Simple question

    You need to loop through the array to check which has been selected, or you can store the index when it is being selected.
    VB Code:
    1. 'Loop through the items.
    2. Dim iSelectedIndex As Integer
    3. For iSelectedIndex = 0 To Option1.UBound
    4.     If Option1(iSelectedIndex).Value = True Then
    5.         'Found the one that is selected, exit the loop
    6.         Exit For
    7.     End If
    8. Next
    9. MsgBox "Selected item has index " & uSelectedIndex
    VB Code:
    1. 'Storing the item when it is being selected
    2. Private iSelectedItem As Integer
    3.  
    4. Private Sub Option1_Click(Index As Integer)
    5.     iSelectedItem = Index
    6. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    13

    Re: Option Button --Simple question

    Thanks a Brazilian! (That's a big number!)

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Option Button --Simple question

    Quote Originally Posted by JW2000
    Thanks a Brazilian! (That's a big number!)
    Oh...? It's just not a south-american fotball (soccer) player then?

    I hope you notice the little typo I made in my first code example...
    VB Code:
    1. MsgBox "Selected item has index " & uSelectedIndex
    2. 'Should of course be:
    3. MsgBox "Selected item has index " & [b]i[/b]SelectedIndex

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