Solved

dupe kill listview, splitting

Posted on 2004-08-18
11
300 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

Technology Partners: 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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

623 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