Results 1 to 21 of 21

Thread: Searching Exact String In Listbox for multiple items and add to another listbox ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Searching Exact String In Listbox for multiple items and add to another listbox ?

    Hi everybody.

    It searches multiple items in the listbox not correctly. Im assuming im going to need to loop through the listbox somehow and find all matching and extact items in listbox3 ?

    I have button for scrape google results 2 listboxes and search button.

    Here is what i have for so far but this is not what i want.

    Code:
     ListBox3.Items.Clear()
    
                If TextBox1.Text.Length > 0 Then
                    For index As Integer = 0 To ListBox1.Items.Count - 1
                        Dim txt = ListBox1.Items(index).ToString()
                        If txt.Contains(TextBox1.Text) Then
                            ListBox3.Items.Add(txt)
                            Label1.Text = ListBox3.Items.Count
                        End If
                    Next
                End If
    look at the picture:

    Name:  K6eq6D.jpg
Views: 1735
Size:  36.1 KB

    it finds Wrong urls and not match in the listbox from textbox.

    How to fix it and make it search exact what i type in textbox and add from listbox1 found items to listbox 3 and count items ?

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    You do realize we have only just started 2015

  3. #3
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    I don't understand what you're trying to do but is sounds like you want to do this;

    Code:
            ListBox3.Items.Clear()
    
            If TextBox1.Text.Length > 0 Then
                For Each ItemText As String In ListBox1.Items
                    If TextBox1.Text.Contains(ItemText) Then
                        ListBox3.Items.Add(ItemText)
                        Label1.Text = ListBox3.Items.Count
                    End If
                Next
            End If
    Last edited by Bulldog; Mar 8th, 2015 at 07:09 AM.


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    The code you gave me does not do anything.
    It doesn,t even add found exact results to listbox3

    Can you suggest another one ?

    Thanks.

  5. #5
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    Well it works fine for me, but then again I have no idea what you're trying to do.

    So let's be specific...

    You have a TextBox containing Text.
    You have a list of Strings in a ListBox called ListBox1.
    You want to see if each String in ListBox1 is present within the text of the TextBox
    If it is present, you want to add that String to a ListBox called ListBox3

    Is that correct?


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    Yes exactly
    But i do not know how to do that Cuz this code doesn't work.
    I want to add not text but as you can see in the picture urls to listbox3 but only matching results of that keywords i type in textbox.

  7. #7
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    The code I gave you does exactly what I said.

    But you want more than that. So let's be specific again...

    If a string in ListBox1 is found within the Text of the TextBox and the string it is within is a URL, then you want the URL added to ListBox3.

    Is that right?


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    Yes,you are right man
    But add to listbox3 only maching results.

  9. #9
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    And the Text within the TextBox is a list of URL's, with one URL per line and not breaking across lines?

    In which case you want something different to what you asked for, so be specific. I think you're looking for something more like this.

    Code:
            ListBox3.Items.Clear()
            If TextBox1.Lines.Count > 0 Then
                For Each line As String In TextBox1.Lines
                    For Each ItemText As String In ListBox1.Items
                        If line.Contains(ItemText) Then
                            ListBox3.Items.Add(line)
                            Label1.Text = ListBox3.Items.Count
                        End If
                    Next
                Next
            End If


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    It's not working man it doesn't add anything any results

  11. #11
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    Again, it works for me, it does exactly what we specified.

    Here is my test code which works fine.

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    
            Dim TextBox1 As New TextBox
            Me.Controls.Add(TextBox1)
            TextBox1.AppendText("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + Environment.NewLine)
            TextBox1.AppendText("abcdefghijklmnopqrstuvwxyz" + Environment.NewLine)
    
            Dim ListBox1 As New ListBox
            ListBox1.Items.Add("AB")
            ListBox1.Items.Add("GH")
            ListBox1.Items.Add("PP")
            ListBox1.Items.Add("VW")
            ListBox1.Items.Add("ab")
            Me.Controls.Add(ListBox1)
    
            Dim ListBox3 As New ListBox
            Me.Controls.Add(ListBox3)
    
            Dim Label1 As New Label
            Me.Controls.Add(Label1)
    
            '*** Start: Here is the code
            ListBox3.Items.Clear()
            If TextBox1.Lines.Count > 0 Then
                For Each line As String In TextBox1.Lines
                    For Each ItemText As String In ListBox1.Items
                        If line.Contains(ItemText) Then
                            ListBox3.Items.Add(line)
                            Label1.Text = ListBox3.Items.Count
                        End If
                    Next
                Next
            End If
            '*** End of code
    
            MessageBox.Show(Label1.Text)
    
            Dim MyList As String = String.Empty
            For Each Item As String In ListBox3.Items
                MyList += Item + Environment.NewLine
            Next
            MessageBox.Show(MyList)
    
        End Sub
    
    End Class
    So what is about the above that does not satisfy the requirement you stated? Show me the code you have written.
    Last edited by Bulldog; Mar 8th, 2015 at 11:33 AM.


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    I want to do that not adding items like this listbox1.items.add ("some text") I do not wanna that cuz i'm scraping google results from google search engine and i want to find using textbox exact match of urls found in listbox one and add exact all matching urls to listbox3 from listbox1 that contains that strings on button click.

    This is exactly what i want to be.
    I hope you will understand that now.

  13. #13
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    Ok, we are going round in circles, the goalposts are moving around the field.

    So...

    The input...
    * ListBox1 contains a list of URL's that you have entered (you must have added them somehow)
    * TextBox1 contains Text, which is actually a list of URL's.

    The output...
    * ListBox3 needs to contain a list of URL's that appear in ListBox1 and are also found in the TextBox Text.

    Is that right?


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    Yes exactly.

    I just want to add exact results in listbox3 from listbox1 when i enter some keyword into textbox one i click button1 to scrape urls from google and add to listbox1 and when i click the buton find it must find and add exact urls from listbox1 to listbox3 which i scraped from google urls.

  15. #15
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    ok, so we go back to this then...

    Code:
            ' You click a button that populates ListBox1
    
            ' You enter some text into the TextBox
    
            ' We clear the results
            ListBox3.Items.Clear()
    
            ' If any URL in ListBox1 contains the Text you typed
            For Each ItemText As String In ListBox1.Items
                If ItemText.Contains(TextBox1.Text) Then
                    ' We add that whole URL to the results
                    ListBox3.Items.Add(ItemText)
                    Label1.Text = ListBox3.Items.Count
                End If
            Next
    Last edited by Bulldog; Mar 8th, 2015 at 12:00 PM.


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    The code is working but it adds not the same urls which is in the listbox1 when click on the url in the listbox3 it opens the link in google chrome but not that but different and i do not why it does that

    When i click on the link in listbox1 it opens correct page in google chrome.
    Sure it shows in the listbox3 correct urls but when i click on the link it open not the same url as shown in listbox3.
    Last edited by polas; Mar 8th, 2015 at 12:33 PM.

  17. #17
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    The code adds whatever is in ListBox1's items, to ListBox3, when a ListBox1 item contains the text present within the TextBox.

    If you click on an entry in ListBox3, it will raise an event, so check the code associated with that event.

    I suspect you are expecting URL's in ListBox3 which matches your TextBox Text, then you need to change one line;

    Code:
                If ItemText = TextBox1.Text Then
    Last edited by Bulldog; Mar 8th, 2015 at 12:15 PM.


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    Can you add all fixed code cuz i do not know that to change and where in that code ?

    Still doesn't work
    I get the same problem.

    Thanks.
    Last edited by polas; Mar 8th, 2015 at 12:48 PM.

  19. #19
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    It's one line.

    Code:
            ' You click a button that populates ListBox1
    
            ' You enter some text into the TextBox
    
            ' We clear the results
            ListBox3.Items.Clear()
    
            ' If any URL in ListBox1 is the same as the Text you typed
            For Each ItemText As String In ListBox1.Items
                If ItemText = TextBox1.Text Then
                    ' We add that whole URL to the results
                    ListBox3.Items.Add(ItemText)
                    Label1.Text = ListBox3.Items.Count
                End If
            Next
    The code does what you specified, so I'm lost as to what you're expecting. But at least now you have many examples of code to implement the function you're looking for, so I'm sure you can work through the code and debug it.


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    It adds nothing

  21. #21
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Searching Exact String In Listbox for multiple items and add to another listbox

    Then run it in debug mode and trace it through. I cannot help you further unless you can specify what you're trying to do or show your code, otherwise I am in the dark guessing.


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

Tags for this Thread

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