'Lo...

having trouble rigging a listbox to handle a variable request...

my code below is 'hardwired' to handle a list of up to 3 items..


Code:
Private Sub listClients_Click()

            If listClients.Selected(0) Then
    
                txtSelected.Text = listClients.Text

            End If
            
            If listClients.Selected(1) Then
    
                txtSelected.Text = listClients.Text

            End If
            
            If listClients.Selected(2) Then
    
                txtSelected.Text = listClients.Text

            End If
End Sub
But what if I don't know the length of the listbox?

Here's what I've tried that doesn't work...

Code:
Private Sub listClients_Click()

  DIM r, k

  k = listClients.listcount

  For r = 0 to k

            If listClients.Selected(r) Then
    
                txtSelected.Text = listClients.Text

            End If
  Next r
            
End Sub
Which gives me a complie error that says that there's an invalid property array index...and it then points to the "If listClients.Selected(r) then" line...

Can someone fine tune this or point me in the right direction?

Thanks...

Jim