Results 1 to 3 of 3

Thread: Detect List

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2010
    Posts
    50

    Detect List

    Helo all
    sir here im having a problem with my result i have 3 list view
    1 for old list data 2nd for new + old list data and 3rd for my result
    i want add new data in my 3rd listview wich not contain my olds list data
    for exmple:

    Code:
    Dim A,B,C
    A = 123456
    B = 12345678910
    NOW I WANT IN C = 78910 ITS MY RESULT

    I SIMPLY MAKE A CODE BT ITS NOT WORK
    Code:
    Private Sub Command1_Click()
    For I = 1 To ListView2.ListItems.Count
    ListView3.ListItems.Add , , ListView2.ListItems(I)
    Next
    On Error Resume Next
        For I = 1 To ListView1.ListItems.Count
        For j = 1 To ListView2.ListItems.Count
        
        If ListView1.ListItems(I) = ListView2.ListItems(j) Then ListView3.ListItems.Remove (I)
        
        Next j
        Next I
        
    End Sub
    
    Private Sub Form_Load()
    For I = 1 To 20
    ListView1.ListItems.Add , , I
    Next I
    For I = 1 To 30
    ListView2.ListItems.Add , , I
    Next I
    End Sub
    Please help me out .... thanks in advance

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Detect List

    First thing to do is to remove the 'On Error Resume Next' statement - it's hiding an 'Index out of Bounds' error.

    It's easier to not add the item to ListView3 if it appears in ListView1 and ListView2
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim i As Integer
    Dim j As Integer
    Dim boDup As Boolean
    For i = 1 To ListView2.ListItems.Count
        boDup = False
        For j = 1 To ListView1.ListItems.Count
            If ListView1.ListItems(j) = ListView2.ListItems(i) Then
                boDup = True
            End If
        Next j
        If boDup = False Then
            ListView3.ListItems.Add , , ListView2.ListItems(i)
        End If
    Next
    End Sub
    
    Private Sub Form_Load()
    Dim i As Integer
    ListView1.ColumnHeaders.Add , , "Column"
    ListView2.ColumnHeaders.Add , , "Column"
    ListView3.ColumnHeaders.Add , , "Column"
    For i = 1 To 20
        ListView1.ListItems.Add , , i
    Next i
    For i = 1 To 30
        ListView2.ListItems.Add , , i
    Next i
    End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2010
    Posts
    50

    Re: Detect List

    thankyou so much sir its work nicely.. :x

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