Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

dupe kill listview, splitting

i am trying to dupe kill a list view that contains items like:


Simon=1
Jenny=2

i want to have it dupe kill if it finds 2 of the same before the =.
0
andyakira
Asked:
andyakira
1 Solution
 
Ryan ChongCommented:
Can you explain more clearly ?

regards
0
 
andyakiraAuthor Commented:
inside my listview it has names=access. i would like to have it check for duplicate names before adding rather then the whole text.

its adding:
------------
andy=999
andy=92983
andy=882993

i only want 1 andy=# in the list.

Andy.
0
 
Ryan ChongCommented:
You can use the FindItem method as i posted in your earlier question to do that. If the FindItem is nothing then add it else do not add it..

clear?

Let me know if you need futher helps

regards
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
andyakiraAuthor Commented:
the find item method is adding dupelicate names (before the =#) im trying to make it kill the whole text if its a duplicate name.
0
 
petoskey-001Commented:
Make sure your listbox sorted property is set to true.  Remember that's a readOnly property, so you have to set it in the IDE form properties...

Private Sub NoDupes()
   LastItem = ""
   x = 0
   While x < List1.ListCount - 1
      ThisItem = List1.List(x)
      EqPos = InStr(ThisItem, "=")
      ThisItem = Mid(ThisItem, 1, EqPos - 1)
      If LastItem = ThisItem Then
         List1.RemoveItem (x)
      Else
         LastItem = ThisItem
         x = x + 1
      End If
   Wend
End Sub
0
 
Ryan ChongCommented:
Try this:

test.txt:

andy=999
me=9700
andy=92983
you=112255
andy=882993
others=25222

then try like:

Dim tmp As String, tmpArr() As String, tmpArr2() As String
    tmp = ReadFileText("C:\test2.txt")
    tmpArr = Split(tmp, vbCrLf, , vbTextCompare)
    For i = 0 To getArrLength(tmpArr)
        tmpArr2 = Split(tmpArr(i), "=", , vbTextCompare)
        If getArrLength(tmpArr2) = 1 Then
            If ListView1.FindItem(tmpArr2(0)) Is Nothing Then
                i = ListView1.ListItems.Count + 1
                ListView1.ListItems.Add i, , tmpArr2(0)
                ListView1.ListItems(i).SubItems(1) = tmpArr2(1)
            End If
        End If
    Next i

Public Function getArrLength(arr() As String) As Long
    On Error GoTo EH
    getArrLength = UBound(arr)
    Exit Function
EH:
    getArrLength = -1
End Function

Public Function ReadFileText(ByVal FileName As String) As String
    On Error GoTo EHandler
    Dim Handle As Integer
    Handle = FreeFile
    Open FileName For Input As #Handle
        ReadFileText = Input$(LOF(Handle), Handle)
        On Error Resume Next
    Close #Handle
    Exit Function
EHandler:
    On Error Resume Next
    Close #Handle
End Function

Hope this helps
0
 
Ryan ChongCommented:
oops, rename:

tmp = ReadFileText("C:\test2.txt")

to your exact file path..

cheers
0
 
JR2003Commented:
The best way to do this is to use the list item 'key' property.
When you add an item to the list set the ListItems key property to the name of the person.
To then test if an item exists just write a function like the one below:
To call it


If ExistsInListView(ListView1.ListItems, sKey) Then
    MsgBox "Item exists in list view"
Else
    MsgBox "Item not found in list view"
End If

Public Function ExistsInListView(Items As ListItems, Key As String) As Boolean  
'Returns true if the items exists in the ListItems collection
   
    On Error GoTo Trap

    With Items
        If .Item(Key).Index > -1 Then
            ExistsInListView = True
        End If
    End With

    GoTo SkipTrap

Trap:
   
    With Err
        If .Number = 35601 Then
            ExistsInListView = False
        else
            MsgBox("Error: " & .Number & vbNewLine & _
                   "Description: " & .Description & vbNewLine & _
                  "Source: " & .Source, vbExclamation, "Error")
        End If
    End With

SkipTrap:

End Function
0
 
andyakiraAuthor Commented:
  ListView1.ListItems(i).SubItems(1) = tmpArr2(1) invalid property value
0
 
Ryan ChongCommented:
the above is just an example, to make the line:

ListView1.ListItems(i).SubItems(1) = tmpArr2(1)

working, you need to add another column (at least 2 columns totally) from your listview control
0
 
andyakiraAuthor Commented:
i forgot i had this question open, thanks for the help guys
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now