Results 1 to 4 of 4

Thread: Unique Values

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    42

    Question

    I have a file with a listing of registry keys. What I would like to do is to sort the list alphabetically and then somehow extract just the unique values(keys).

    The first list:
    fish
    clams
    turkey
    fish
    fish

    The final list:
    clams
    fish
    turkey

    Any help is welcome - I'm experencing a brain fart!!

    OldMan
    Using VB6 Professional Ediion

  2. #2
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    The first list:
    fish
    clams
    turkey
    fish
    fish

    The final list:
    clams
    fish
    turkey


    Code:
    'put this in the decleration section of your form
    Dim IntFish as integer
    Dim IntClams as integer
    Dim Int Fish as integer
    
    
    'put this into the function thing
    list1.list = IntClams & IntFish & IntTurkey
    
    
    'I hope that this helps as integer
    NXSupport - Your one-stop source for computer help

  3. #3
    Lively Member
    Join Date
    May 1999
    Location
    Singapore
    Posts
    116
    you can try this

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim x() As String
    Dim i As Integer
    Dim j As Integer
    Dim temp As String
    Erase x
    ReDim x(0 To List1.ListCount - 1)
    For i = 0 To List1.ListCount - 1 Step 1
        x(i) = List1.List(i)
    Next i
    'Sort the list
    For i = 0 To UBound(x) Step 1
        For j = i To UBound(x) Step 1
            If CompareString(x(i), x(j)) Then
                temp = x(i)
                x(i) = x(j)
                x(j) = temp
            End If
        Next j
    Next i
    'Get Unique Items
    List1.Clear
    For i = 0 To UBound(x) Step 1
        temp = x(i)
        For j = 0 To List1.ListCount - 1 Step 1
            If x(i) = List1.List(j) Then temp = Empty
        Next j
        If temp <> Empty Then List1.AddItem temp
    Next i
    End Sub
    
    Private Function CompareString(Str1 As String, Str2 As String) As Boolean
    Dim i As Integer
    For i = 1 To Len(Str1) Step 1
        If Asc(Mid(Str1, i, 1)) > Asc(Mid(Str2, i, 1)) Then
            CompareString = True
            Exit Function
        ElseIf Asc(Mid(Str1, i, 1)) < Asc(Mid(Str2, i, 1)) Then
            CompareString = False
            Exit Function
        End If
    Next i
    End Function
    
    Private Sub Form_Load()
    List1.AddItem "fish"
    List1.AddItem "clams"
    List1.AddItem "turkey"
    List1.AddItem "fish"
    List1.AddItem "fish"
    End Sub
    YC Sim
    Teenage Programmer
    UIN 37903254



  4. #4
    Guest

    another way..

    I use ListViews in REPORT view a lot for this sort (sic) of thing.
    for each name you have, you can do a FINDITEM on a listview, if the finditem fails (doesnt exist already) then add it the the listview. [ TRIM your input names first!]
    If you have SORT= true then the list is sorted also
    Also you can very quickly see the results Visible=true
    which is VERY useful for debug!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width