Results 1 to 6 of 6

Thread: Listbox Censor List

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Listbox Censor List

    Hi guys,

    I was wondering....

    Well, i have a listbox with data....and what i would like to do is to check if text1 has any string inside it that matches the list1 items?

    Maybe a good idea would be to go from i=1 to List1.listcount... and then if text1.find (list1(i).text)....ecc?

    what do u think?


    Cheers
    Thanks for helping me out.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Listbox Censor List

    Try this
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long
    
    Private Const LB_FINDSTRINGEXACT = &H1A2
    
    Private Sub AddToListbox(strListBItem As String, LB As ListBox)
    
        Dim lngListIndex As Long
        
        ' lngListIndex is the ListIndex if the item is found
        lngListIndex = SendMessage(LB.hwnd, LB_FINDSTRINGEXACT, -1, ByVal strListBItem)
        If lngListIndex = -1 Then
            LB.AddItem strListBItem
        Else
            MsgBox strListBItem & " is already in the Listbox"
            Exit Sub
        End If
    End Sub
    
    Private Sub Command1_Click()
    AddToListBox Text1.Text, List1
    End Sub

  3. #3

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Listbox Censor List

    Post #3 uses a For/Next loop

  5. #5

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Listbox Censor List

    Hehehehehe....


    Thanks guys... i will try it now
    Thanks for helping me out.

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