1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Merging two Textboxes + Deleting duplicates

Discussion in 'Visual Basic 6' started by kimkils, Nov 27, 2009.

  1. kimkils

    kimkils Power Member

    Joined:
    Jan 10, 2009
    Messages:
    663
    Likes Received:
    225
    I have been trying in vain to do the following:

    Textbox A: Has hundreds of Youtube Video IDs
    Textbox B: Has less Youtube Video IDs

    I want to click a button and then have a new text box populated with all the Video IDs in textbox A that are NOT in Textbox B... sounds simple...

    So far ive made two arrays and a nested for next loop, it's not working as i want though which is frustrating.

    I'm willing to pay for your trouble if someone can get this working, and give me commented code so i understand what's going on.

    My code so far:

    Code:
    Dim splitIDs, splitMerged
        Dim temp, temp2 As String
        Dim foundMatch As Boolean
        Dim retval As Integer
        
        splitIDs = Split(TextIDs.Text, vbCrLf) '  This is Textbox A
        splitMerged = Split(TextMerged.Text, vbCrLf) '  This is Textbox B
        
        For x = 0 To UBound(splitIDs)
        
            temp = splitIDs(x)
        
                For y = 0 To UBound(splitMerged)
                
                    temp2 = splitMerged(y)
                    
                    Log ("temp  is: " & temp)
                    Log ("temp2 is: " & temp2)
                    
                    retval = InStr(1, temp, temp2) ' Returns 1 if match, 0 if not
                    
                    Log ("Result for compare was: " & retval)
                    
                    Select Case retval
                        Case 0:
                            foundMatch = False
                            Log ("I think " & temp & " & " & temp2 & " are different")
                            TextResult.Text = TextResult.Text & vbCrLf & temp
                        Case 1:
                            Log ("I think " & temp & " & " & temp2 & " are same")
                            foundMatch = True: Exit For
                    End Select        
                Next y   
        Next x
    It occasionally throws a 1, even though they arent the same, and debugging it i see it's because sometimes it reads a blank space from "TextBox B"
    Plus it prints LOADS of each one, when it shouldnt...

    It's a long shot asking for help but i'm pulling my hair out :)

    Thanks :)
     
  2. howdoyou

    howdoyou Regular Member

    Joined:
    Nov 17, 2008
    Messages:
    284
    Likes Received:
    57
    Occupation:
    Programming
    Location:
    Kentucky
    Code:
    Private Sub Command1_Click()
        Dim ItsThere As Boolean
        For i = 0 To List1.ListCount - 1
            For x = 0 To List2.ListCount - 1
                If List1.List(i) = List2.List(x) Then
                    ItsThere = True
                End If
            Next
            If ItsThere = True Then
                'do nothing...
            Else
                List3.AddItem List1.List(i)
            End If
            ItsThere = False
        Next
    End Sub
    
    Private Sub Form_Load()
        List1.AddItem "a"
        List1.AddItem "b"
        List1.AddItem "c"
        List1.AddItem "d"
        List1.AddItem "e"
        List1.AddItem "f"
        List1.AddItem "g"
        List1.AddItem "h"
        List1.AddItem "i"
        List1.AddItem "j"
        List1.AddItem "k"
        
        
        
        List2.AddItem "b"
        List2.AddItem "d"
        List2.AddItem "k"
        List2.AddItem "g"
    End Sub
    
    
     
    • Thanks Thanks x 1