Solved

dupe kill listview, splitting

Posted on 2004-08-18
11
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 11838107
Can you explain more clearly ?

regards
0
 

Author Comment

by:andyakira
ID: 11838132
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 52

Expert Comment

by:Ryan Chong
ID: 11838190
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:andyakira
ID: 11838224
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
ID: 11838260
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
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 11838434
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 52

Expert Comment

by:Ryan Chong
ID: 11838438
oops, rename:

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

to your exact file path..

cheers
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11839761
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
ID: 11846940
  ListView1.ListItems(i).SubItems(1) = tmpArr2(1) invalid property value
0
 
LVL 52

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 11848749
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
ID: 11862526
i forgot i had this question open, thanks for the help guys
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

740 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