Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

VS 2010 Ability to narrow search using textboxes

$
0
0
Hi I am creating a search program ( attempting to ) and I am stumped. Im new to programming as my code will probably show. I am looking to be able to narrow a search based on what is typed in multiple text boxes and have the files that have the keywords in them show in a list box. If I use just one text box and put in a keyword it works great but when I use multiple text boxes it expands my search rather than narrowing it down. For example if I search for the word blue I will get the list of all files that contain the word blue. If I search for blue and then put red in the other text box I get all files that have blue or red instead of narrowing it down to only files that have the words blue and red in it. I am very bad at explaining things I really hope I explained this well enough. Thank you in advance and please be easy on me as I am new. lol.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strsearchone As String = txtsearchone.Text
Dim strsearchtwo As String = txtsearchtwo.Text
Dim strsearchthree As String = txtsearchthree.Text
Dim strsearchfour As String = txtsearchfour.Text
Dim strCC As String = lstboxCC.Text
MessageBox.Show(strCC)
Dim list As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
Dim list2 As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
Dim list3 As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
Dim list4 As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
'Dim listtest As System.Collections.ObjectModel.ReadOnlyCollection(Of String)

If strCC = "" Then
MessageBox.Show("No month selected. Closing")
Me.Close()
Exit Sub
End If

list = My.Computer.FileSystem.FindInFiles("k:\samsheet\" & strCC, strsearchone, True, FileIO.SearchOption.SearchAllSubDirectories)
list2 = My.Computer.FileSystem.FindInFiles("k:\samsheet\" & strCC, strsearchtwo, True, FileIO.SearchOption.SearchAllSubDirectories)
list3 = My.Computer.FileSystem.FindInFiles("k:\samsheet\" & strCC, strsearchthree, True, FileIO.SearchOption.SearchAllSubDirectories)
list4 = My.Computer.FileSystem.FindInFiles("k:\samsheet\" & strCC, strsearchfour, True, FileIO.SearchOption.SearchAllSubDirectories)
'listtest = My.Computer.FileSystem.FindInFiles("k:\samsheet\" & strCC, strsearchone & strsearchtwo, True, FileIO.SearchOption.SearchAllSubDirectories)

'MessageBox.Show(listtest)

If txtsearchone.Text = "" Then
MessageBox.Show("Nothing chosen")
Else
For Each Name As String In list
'ListBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(Name))
ListBox1.Items.Add(System.IO.Path.GetFileName(Name))
Next
End If

If txtsearchtwo.Text = "" Then
'MessageBox.Show("Nothing chosen")
Else
For Each Name As String In list2
'ListBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(Name))
ListBox1.Items.Add(System.IO.Path.GetFileName(Name))
Next
End If

If txtsearchthree.Text = "" Then
'MessageBox.Show("Nothing chosen")
Else
For Each Name As String In list3
'ListBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(Name))
ListBox1.Items.Add(System.IO.Path.GetFileName(Name))
Next
End If

If txtsearchfour.Text = "" Then
'MessageBox.Show("Nothing chosen")
Else
For Each Name As String In list4
'ListBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(Name))
ListBox1.Items.Add(System.IO.Path.GetFileName(Name))
Next
End If

MessageBox.Show("Search Complete")
txtboxcount.Text = ListBox1.Items.Count
End Sub

Viewing all articles
Browse latest Browse all 27349

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>