none
help search text RRS feed

  • Question

  • hello

    I want to search for value from textbox
    search = "54 49 57 52 49"
    I want to search for the value in this texts and if it finds the value of

    A860000 : 53/
    A860001 : 48
    A860002 : 48
    A860003 : 48
    A860004 : 50
    A860005 : 54
    A860006 : 49
    A860007 : 57
    A860008 : 52
    A860009 : 49
    A86000A : 49
    A86000B : 55
    A86000C : 49
    A86000D : 52
    A86000E : 50
    A86000F : 57
    A860010 : 55
    A860011 : 51
    A860012 : 49

    add value to listbox

    i use code but not work

            Dim search As String = "54 49 57 52 49"
            Dim _replace As String = "12 12 12 12 12"
            Dim z As String = ""
            Dim a = Regex.Split(TextBox1.Text, Environment.NewLine)
    
            For Each i As String In a
                If i.Length > 2 Then z += i.Substring(i.Length - 2)
            Next
    
            If z.Contains(search.Replace(" ", "")) Then
                z.Replace(search.Replace(" ", ""), _replace.Replace(" ", ""))
            Else
                MsgBox("Not Found !!")
                GoTo ameer
            End If
    
    
            Dim d As Integer = 860000
    
            For i As Integer = 0 To z.Length - 1 Step 2
                ListBox1.Items.Add("A" & d & " : " & z.Substring(i, 2))
                d += 1
            Next
    ameer:

    Friday, September 6, 2019 6:38 PM

Answers

  • Hi

    Here is myn understanding of your question.

    ' Form1 with TextBox1,
    ' ListBox1, ListBox2
    ' and Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
    	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		TextBox1.Text = "54 49 57 52 49"
    		ListBox1.Items.AddRange({"A860000: 53",
    "A860001: 48",
    "A860002: 48",
    "A860003: 48",
    "A860004: 50",
    "A860005: 54",
    "A860006: 49",
    "A860007: 57",
    "A860008: 52",
    "A860009: 49",
    "A86000A: 49",
    "A86000B: 55",
    "A86000C: 49",
    "A86000D: 52",
    "A86000E: 50",
    "A86000F: 57",
    "A860010: 55",
    "A860011: 51",
    "A860012: 49"})
    	End Sub
    
    	Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    		ListBox2.Items.Clear()
    		Dim s() As String = Split(TextBox1.Text, " "c)
    		For Each i As String In ListBox1.Items
    			For Each j As String In s
    				If i.EndsWith(j) Then
    					If Not ListBox2.Items.Contains(i) Then ListBox2.Items.Add(i)
    				End If
    			Next
    		Next
    	End Sub
    End Class


    Regards Les, Livingston, Scotland

    Saturday, September 7, 2019 12:56 PM
  • Hi

    OK, try this one

    ' Form1 with TextBox1,
    ' ListBox1, ListBox2
    ' and Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            TextBox1.Text = "54 49 57 52 49 50 50"
            ListBox1.Items.AddRange({"A860000: 53",
    "A860001: 48",
    "A860002: 48",
    "A860003: 48",
    "A860004: 50",
    "A860005: 54",
    "A860006: 49",
    "A860007: 57",
    "A860008: 52",
    "A860009: 49",
    "A86000A: 49",
    "A86000B: 55",
    "A86000C: 49",
    "A86000D: 52",
    "A86000E: 50",
    "A86000F: 57",
    "A860010: 55",
    "A860011: 51",
    "A860012: 49"})
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ListBox2.Items.Clear()
            Dim s, t As New List(Of String)
            s = TextBox1.Text.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries).ToList
            t.AddRange(s)
            For Each i As String In ListBox1.Items
                For Each j As String In s
                    If i.EndsWith(j) Then
                        If Not ListBox2.Items.Contains(i) Then
                            If t.Contains(j) Then
                                ListBox2.Items.Add(i)
                                t.Remove(j)
                            End If
                        End If
                    End If
                Next
            Next
        End Sub
    End Class



    Regards Les, Livingston, Scotland





    • Edited by leshay Sunday, September 8, 2019 1:38 PM
    • Marked as answer by programmervb.net Sunday, September 8, 2019 7:57 PM
    Sunday, September 8, 2019 11:50 AM

All replies

  • Hi

    Your "54 49 57 52 49" - one single string - do you mean you want to split that into 54, 49, 57, 52, 49 separate search terms and then search through the list to find if any of the strings in the list CONTAIN the search term?


    Regards Les, Livingston, Scotland

    Friday, September 6, 2019 6:47 PM
  • Hi,

    I'm not sure if I can understand what you want to do.
    I made a sample from my guess.
        
    ' --- Form: Load
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	Me.TextBox1.Text _
    		= " 54" & vbCrLf _
    		& " 49" & vbCrLf _
    		& " 57" & vbCrLf _
    		& " 52"
    	Me.TextBox2.Text _
    		= "A860000 : 53" & vbCrLf _
    		& "A860001 : 48" & vbCrLf _
    		& "A860002 : 48" & vbCrLf _
    		& "A860003 : 52" & vbCrLf _
    		& "A860004 : 50" & vbCrLf _
    		& "A860005 : 55" & vbCrLf _
    		& "A860006 : 49" & vbCrLf _
    		& "A860007 : 57" & vbCrLf _
    		& "A860008 : 52" & vbCrLf _
    		& "A860009 : 49" & vbCrLf _
    		& "A86000A : 49" & vbCrLf _
    		& "A86000B : 55" & vbCrLf _
    		& "A86000C : 49"
    End Sub
    ' --- [Button1]
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    	Me.ListBox1.Items.Clear()
    	' ---
    	Dim searchBy As String
    	Dim searchFor As String
    	Dim pos As Integer
    	Dim result As String
    	' ---
    	For i As Integer = 0 To Me.TextBox1.Lines.Length - 1
    		searchBy = Me.TextBox1.Lines(i)
    		For n As Integer = 0 To Me.TextBox2.Lines.Length - 1
    			searchFor = Me.TextBox2.Lines(n)
    			pos = searchFor.IndexOf(searchBy)
    			If (pos > 0) Then
    				result = searchFor.Remove(pos, Len(searchBy))
    				result = result.Insert(pos, " 12")
    				Me.ListBox1.Items.Add(result)
    			End If
    		Next
    	Next
    End Sub
    I hope you will explain what you want to do more concrete.

    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Saturday, September 7, 2019 1:43 AM
  • Hi,

    I'm not sure if I can understand what you want to do.
    I made a sample from my guess.
        
    ' --- Form: Load
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	Me.TextBox1.Text _
    		= " 54" & vbCrLf _
    		& " 49" & vbCrLf _
    		& " 57" & vbCrLf _
    		& " 52"
    	Me.TextBox2.Text _
    		= "A860000 : 53" & vbCrLf _
    		& "A860001 : 48" & vbCrLf _
    		& "A860002 : 48" & vbCrLf _
    		& "A860003 : 52" & vbCrLf _
    		& "A860004 : 50" & vbCrLf _
    		& "A860005 : 55" & vbCrLf _
    		& "A860006 : 49" & vbCrLf _
    		& "A860007 : 57" & vbCrLf _
    		& "A860008 : 52" & vbCrLf _
    		& "A860009 : 49" & vbCrLf _
    		& "A86000A : 49" & vbCrLf _
    		& "A86000B : 55" & vbCrLf _
    		& "A86000C : 49"
    End Sub
    ' --- [Button1]
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    	Me.ListBox1.Items.Clear()
    	' ---
    	Dim searchBy As String
    	Dim searchFor As String
    	Dim pos As Integer
    	Dim result As String
    	' ---
    	For i As Integer = 0 To Me.TextBox1.Lines.Length - 1
    		searchBy = Me.TextBox1.Lines(i)
    		For n As Integer = 0 To Me.TextBox2.Lines.Length - 1
    			searchFor = Me.TextBox2.Lines(n)
    			pos = searchFor.IndexOf(searchBy)
    			If (pos > 0) Then
    				result = searchFor.Remove(pos, Len(searchBy))
    				result = result.Insert(pos, " 12")
    				Me.ListBox1.Items.Add(result)
    			End If
    		Next
    	Next
    End Sub
    I hope you will explain what you want to do more concrete.

    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.htmln

    not new line search all values in line one

    Saturday, September 7, 2019 2:02 AM
  • I cannot understand your explanation.

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Saturday, September 7, 2019 2:52 AM
  • I cannot understand your explanation.

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Saturday, September 7, 2019 3:29 AM
  • Hi

    Here is myn understanding of your question.

    ' Form1 with TextBox1,
    ' ListBox1, ListBox2
    ' and Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
    	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		TextBox1.Text = "54 49 57 52 49"
    		ListBox1.Items.AddRange({"A860000: 53",
    "A860001: 48",
    "A860002: 48",
    "A860003: 48",
    "A860004: 50",
    "A860005: 54",
    "A860006: 49",
    "A860007: 57",
    "A860008: 52",
    "A860009: 49",
    "A86000A: 49",
    "A86000B: 55",
    "A86000C: 49",
    "A86000D: 52",
    "A86000E: 50",
    "A86000F: 57",
    "A860010: 55",
    "A860011: 51",
    "A860012: 49"})
    	End Sub
    
    	Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    		ListBox2.Items.Clear()
    		Dim s() As String = Split(TextBox1.Text, " "c)
    		For Each i As String In ListBox1.Items
    			For Each j As String In s
    				If i.EndsWith(j) Then
    					If Not ListBox2.Items.Contains(i) Then ListBox2.Items.Add(i)
    				End If
    			Next
    		Next
    	End Sub
    End Class


    Regards Les, Livingston, Scotland

    Saturday, September 7, 2019 12:56 PM
  • Hi

    Here is myn understanding of your question.

    ' Form1 with TextBox1,
    ' ListBox1, ListBox2
    ' and Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
    	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		TextBox1.Text = "54 49 57 52 49"
    		ListBox1.Items.AddRange({"A860000: 53",
    "A860001: 48",
    "A860002: 48",
    "A860003: 48",
    "A860004: 50",
    "A860005: 54",
    "A860006: 49",
    "A860007: 57",
    "A860008: 52",
    "A860009: 49",
    "A86000A: 49",
    "A86000B: 55",
    "A86000C: 49",
    "A86000D: 52",
    "A86000E: 50",
    "A86000F: 57",
    "A860010: 55",
    "A860011: 51",
    "A860012: 49"})
    	End Sub
    
    	Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    		ListBox2.Items.Clear()
    		Dim s() As String = Split(TextBox1.Text, " "c)
    		For Each i As String In ListBox1.Items
    			For Each j As String In s
    				If i.EndsWith(j) Then
    					If Not ListBox2.Items.Contains(i) Then ListBox2.Items.Add(i)
    				End If
    			Next
    		Next
    	End Sub
    End Class


    Regards Les, Livingston, Scotland

    This code is good but how to output the specified value in search textbox1 without entering any values
    Saturday, September 7, 2019 8:49 PM
  • his code is good but how to output the specified value in search textbox1 without entering any values

    Hi

    What do you mean?

    Show an example of what you want.


    Regards Les, Livingston, Scotland

    Saturday, September 7, 2019 9:05 PM
  • his code is good but how to output the specified value in search textbox1 without entering any values

    Hi

    What do you mean?

    Show an example of what you want.


    Regards Les, Livingston, Scotland

    The code that entered the increment values is not in the search text, go to the image me There are no more values I want like exactly in the picture


    Saturday, September 7, 2019 9:52 PM
  • Hi

    Please explain why one of the values is repeated and not the others? You seem to have flexible goal posts.

    This is as close as I have. It produces 4 results and not the 5 that you seem to suggest is required.

    ' Form1 with TextBox1,
    ' ListBox1, ListBox2
    ' and Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            TextBox1.Text = "54 49 57 52 49"
            ListBox1.Items.AddRange({"A860000: 53",
    "A860001: 48",
    "A860002: 48",
    "A860003: 48",
    "A860004: 50",
    "A860005: 54",
    "A860006: 49",
    "A860007: 57",
    "A860008: 52",
    "A860009: 49",
    "A86000A: 49",
    "A86000B: 55",
    "A86000C: 49",
    "A86000D: 52",
    "A86000E: 50",
    "A86000F: 57",
    "A860010: 55",
    "A860011: 51",
    "A860012: 49"})
        End Sub

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ListBox2.Items.Clear()
            Dim s() As String = Split(TextBox1.Text, " "c)
            Dim t As New List(Of String)
            For Each i As String In ListBox1.Items
                For Each j As String In s
                    If i.EndsWith(j) Then
                        If Not ListBox2.Items.Contains(i) Then
                            If Not t.Contains(j) Then ListBox2.Items.Add(i)
                            t.Add(j)
                        End If
                    End If
                Next
            Next
        End Sub
    End Class


    Regards Les, Livingston, Scotland



    • Edited by leshay Saturday, September 7, 2019 11:06 PM Re-used same code as previous example
    Saturday, September 7, 2019 10:58 PM
  • Hi

    Please explain why one of the values is repeated and not the others? You seem to have flexible goal posts.

    This is as close as I have. It produces 4 results and not the 5 that you seem to suggest is required.

    ' Form1 with TextBox1,
    ' ListBox1, ListBox2
    ' and Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            TextBox1.Text = "54 49 57 52 49"
            ListBox1.Items.AddRange({"A860000: 53",
    "A860001: 48",
    "A860002: 48",
    "A860003: 48",
    "A860004: 50",
    "A860005: 54",
    "A860006: 49",
    "A860007: 57",
    "A860008: 52",
    "A860009: 49",
    "A86000A: 49",
    "A86000B: 55",
    "A86000C: 49",
    "A86000D: 52",
    "A86000E: 50",
    "A86000F: 57",
    "A860010: 55",
    "A860011: 51",
    "A860012: 49"})
        End Sub

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ListBox2.Items.Clear()
            Dim s() As String = Split(TextBox1.Text, " "c)
            Dim t As New List(Of String)
            For Each i As String In ListBox1.Items
                For Each j As String In s
                    If i.EndsWith(j) Then
                        If Not ListBox2.Items.Contains(i) Then
                            If Not t.Contains(j) Then ListBox2.Items.Add(i)
                            t.Add(j)
                        End If
                    End If
                Next
            Next
        End Sub
    End Class


    Regards Les, Livingston, Scotland



    Thank you very much for your cooperation with me and effort but In value is not available A860009: 49 in listbox2 
    Saturday, September 7, 2019 11:55 PM
  • Thank you very much for your cooperation with me and effort but In value is not available A860009: 49 in listbox2 

    Hi

    Should A860009: 49 be in ListBox2 or not?


    Regards Les, Livingston, Scotland

    Sunday, September 8, 2019 12:08 AM
  • Thank you very much for your cooperation with me and effort but In value is not available A860009: 49 in listbox2 

    Hi

    Should A860009: 49 be in ListBox2 or not?


    Regards Les, Livingston, Scotland

    yes Should A860009: 49 be in ListBox2

     TextBox1.Text = "54 49 57 52 49"

    "A860005: 54",
    "A860006: 49",
    "A860007: 57",
    "A860008: 52",
    "A860009: 49",

    Sunday, September 8, 2019 1:10 AM
  • Hi

    OK, try this one

    ' Form1 with TextBox1,
    ' ListBox1, ListBox2
    ' and Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            TextBox1.Text = "54 49 57 52 49 50 50"
            ListBox1.Items.AddRange({"A860000: 53",
    "A860001: 48",
    "A860002: 48",
    "A860003: 48",
    "A860004: 50",
    "A860005: 54",
    "A860006: 49",
    "A860007: 57",
    "A860008: 52",
    "A860009: 49",
    "A86000A: 49",
    "A86000B: 55",
    "A86000C: 49",
    "A86000D: 52",
    "A86000E: 50",
    "A86000F: 57",
    "A860010: 55",
    "A860011: 51",
    "A860012: 49"})
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ListBox2.Items.Clear()
            Dim s, t As New List(Of String)
            s = TextBox1.Text.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries).ToList
            t.AddRange(s)
            For Each i As String In ListBox1.Items
                For Each j As String In s
                    If i.EndsWith(j) Then
                        If Not ListBox2.Items.Contains(i) Then
                            If t.Contains(j) Then
                                ListBox2.Items.Add(i)
                                t.Remove(j)
                            End If
                        End If
                    End If
                Next
            Next
        End Sub
    End Class



    Regards Les, Livingston, Scotland





    • Edited by leshay Sunday, September 8, 2019 1:38 PM
    • Marked as answer by programmervb.net Sunday, September 8, 2019 7:57 PM
    Sunday, September 8, 2019 11:50 AM