Solved

dupe kill listview, splitting

Posted on 2004-08-18
11
293 Views
Last Modified: 2010-05-02
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
Comment
Question by:andyakira
11 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Can you explain more clearly ?

regards
0
 

Author Comment

by:andyakira
Comment Utility
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
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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
 

Author Comment

by:andyakira
Comment Utility
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
 
LVL 7

Expert Comment

by:petoskey-001
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
oops, rename:

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

to your exact file path..

cheers
0
 
LVL 18

Expert Comment

by:JR2003
Comment Utility
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
 

Author Comment

by:andyakira
Comment Utility
  ListView1.ListItems(i).SubItems(1) = tmpArr2(1) invalid property value
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 500 total points
Comment Utility
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
 

Author Comment

by:andyakira
Comment Utility
i forgot i had this question open, thanks for the help guys
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now