Results 1 to 4 of 4

Thread: Listbox Loop

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Cairns,North Queensland, Australia
    Posts
    21

    why won't this remove the items from list2.

    Private Sub Command1_Click()
    Dim i As Integer

    For i = 0 To List1.ListCount - 1
    list2.RemoveItem i

    Next i


    End Sub

  2. #2
    Guest
    Maybe because List1 has more items than List2. Is this the case with you?

  3. #3
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219
    No Megatron. Even if List1.RemoveItem i is used, the same error will occur. I had this problem myself.

    It is because List2.ListCount decreases when the list items are removed. List2.ListCount is less than i at one point.

    Use this code to solve your problem.

    Code:
    Private Sub Command1_Click() 
    Dim i As Integer 
    For i = 0 To List1.ListCount - 1 
       List2.RemoveItem 1
    Next i 
    End Sub
    [Edited by shafee on 11-17-2000 at 08:14 PM]

  4. #4
    Lively Member
    Join Date
    Jan 1999
    Location
    Burlington, IA, USA`
    Posts
    77

    list box

    'try this

    Private Sub Command1_Click()
    Dim i As Integer
    Form1.Show
    For i = 0 To List1.ListCount - 1
    List2.RemoveItem 0
    Next i
    End Sub
    An ass may bray a good long time before he shakes the stars down.
    T.S. Elliot

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