Solved

dupe kill listview, splitting

Posted on 2004-08-18
11
295 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
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 49

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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 49

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 49

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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

911 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

16 Experts available now in Live!

Get 1:1 Help Now