Results 1 to 3 of 3

Thread: Retrieve index from an array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    110

    Retrieve index from an array

    Hi

    Could anyone please tell me how to store a certain index value in an integer?

    I am trying to retrieve the index of the selected radio button from an array of radio buttons.


    Thanks

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Retrieve index from an array

    Code:
    Dim i As Integer
    
    For i = Option1.LBound To Option1.UBound
        If Option1(i).Value = True Then
            MsgBox "You selected Option " & i
            Exit For
        End If
    Next i

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Retrieve index from an array

    Or you could set up a simple little Property to store the Index that is selected.

    Code:
    Option Explicit
    Private mintIndex As Integer
    
    Private Sub Command1_Click()
    
        MsgBox "The radio button with Index " & RadioButtonSelected & " is selected."
    End Sub
    
    Public Property Get RadioButtonSelected() As Integer
    
        RadioButtonSelected = mintIndex
        
    End Property
    
    Public Property Let RadioButtonSelected(ByVal intIndex As Integer)
    
        mintIndex = intIndex
    
    End Property
    
    Private Sub Option1_Click(Index As Integer)
    
        RadioButtonSelected = Index
    
    End Sub

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