Results 1 to 8 of 8

Thread: [RESOLVED] help with 2 list box checking if contains

  1. #1

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Resolved [RESOLVED] help with 2 list box checking if contains

    having little trouble detecting


    list1 items

    site1.com
    site2.com
    site3.com



    list2 items
    <a href="http://www.site1.com/">free- Free general Directory</a>
    <a href="http://www.site2.com/">red- Free turn Directory</a>



    using this code now


    Code:
    Dim BoolAdd As Boolean, i As Long, J As Long
        On Error Resume Next
    
         
        For i = List1.ListCount - 1 To 0 Step -1
           For J = 0 To List2.ListCount
              If List1.List(i) = List2.List(J) Then
                  
                 List1.RemoveItem (i)
    
                 Exit For
              
              End If
            
              DoEvents
           Next J
           DoEvents
        Next i

    cant get it to work because list2 has < > and other chars please help

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: help with 2 list box checking if contains

    I believe you already know how to use InStr, right?
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: help with 2 list box checking if contains

    For i = List1.ListCount - 1 To 0 Step -1
    For J = 0 To List2.ListCount

    If InStr(List1.List(i), List2.list(i)) Then

    List2.RemoveItem (i)

    Exit For

    End If

    DoEvents
    Next J
    DoEvents
    Next i


    not happening


    tried
    Dim i As Integer

    For i = 0 To List1.ListCount - 1
    If InStr(List1.List(i), "site2.com") Then
    List1.Selected(i) = True
    MsgBox "Item #" & (i + 1) & " is what you searched for"
    'Select the found entry
    List1.ListIndex = i
    End If
    Next

    it works but the line were it shows "site2.com") Then need to add list2.list(i) something like that to scan all list2 and match
    Last edited by ladoo; Jun 14th, 2013 at 03:09 AM.

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: help with 2 list box checking if contains

    Refer to the link I've given. Read carefully the descriptions of the string1 and string2 parameters. You'll then see why it didn't work.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: help with 2 list box checking if contains

    comon just little stuck want to get out of the mud hole am in and move on

  6. #6

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: help with 2 list box checking if contains

    taraaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

    done it

    Code:
    Private Sub Command17_Click()
    Dim i As Integer, x As Integer
    
    For i = 0 To List4.ListCount - 1
    For x = 0 To List5.ListCount - 1
    If InStr(List4.List(i), List5.List(x)) > 0 Then
      'If InStr(List4.List(i), List5.List(i)) Then
      
        List5.RemoveItem (x)
        Exit For
      End If
    Next
    Next
    End Sub

  7. #7
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] help with 2 list box checking if contains

    Just swap the arguments:

    Code:
    If InStr(List2.List(J), List1.List(i)) Then
    Note List2's J index.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  8. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,263

    Re: [RESOLVED] help with 2 list box checking if contains

    There are more than just the one obvious mistake. I've corrected it

    Code:
    If InStr(List2.List(j), List1.list(i)) Then
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

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