Results 1 to 6 of 6

Thread: Problems with listBox???

  1. #1

    Thread Starter
    Addicted Member JVRudnick's Avatar
    Join Date
    Oct 2001
    Location
    Toronto, Canada
    Posts
    135

    Problems with listBox???

    '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
    Jim Rudnick
    MCSD
    KKT INTERACTIVE
    www.kkti.com

  2. #2
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210
    make
    k=listclients.listcount-1

    because the listbox starts at zero, not one.


    -George
    < o >

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Make sure txtSelected is set to MultiLine.
    VB Code:
    1. Private Sub listClients_Click()
    2. Dim i As Long
    3. For i = listClients.ListCount - 1 To 0 Step -1
    4.     If listClients.Selected(i) = True Then
    5.       txtSelected.Text = listClients.List(lstClients.ListIndex)
    6.     End If
    7. Next
    8. End Sub

  4. #4

    Thread Starter
    Addicted Member JVRudnick's Avatar
    Join Date
    Oct 2001
    Location
    Toronto, Canada
    Posts
    135

    Thanks!

    Hmm....

    Thanks...remembered to start my hardwired one with (0) but never thought of that fix!

    Tip-O-the-Hat!

    Jim
    Jim Rudnick
    MCSD
    KKT INTERACTIVE
    www.kkti.com

  5. #5
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    Why are you checking for its list index?????


    all you need is:



    txtSelected.Text = listClients.Text


    This will work with any number of entries... I dont see why you have the if statements?
    Leather Face is comin...


    MCSD

  6. #6

    Thread Starter
    Addicted Member JVRudnick's Avatar
    Join Date
    Oct 2001
    Location
    Toronto, Canada
    Posts
    135

    <grin> Never mind...

    Nevermind -- got it myownself!


    ;-)



    Jim
    Jim Rudnick
    MCSD
    KKT INTERACTIVE
    www.kkti.com

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