Page 1 of 1

Search function [help in VB-2010]

Posted: Mon Aug 13, 2012 9:09 pm
by CodenBoy
Helloooo, :D

I just got stuck in my app, cuz i dont know how to make a search function, like if i wrote "test" in textbox1 and press a button , it will put ALL the "test" . (ALL file types)
Image
http://imgur.com/xkQiG

like the image <<
thanks

Re: Search function [help in VB-2010]

Posted: Mon Aug 13, 2012 9:30 pm
by Filip
How would you like to display results?

Re: Search function [help in VB-2010]

Posted: Mon Aug 13, 2012 9:39 pm
by CodenBoy
in the listbox, look in the picture, if i wrote "test" in the TEXTBOX1 then press BUTTON1 all search found will be in Listbox1 with full location, see the pic and u will know, thx :D

Re: Search function [help in VB-2010]

Posted: Tue Aug 14, 2012 8:34 am
by DeveloperJacob
Maybe this code helps:
Code: Select all
For Each File In My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.Desktop, FileIO.SearchOption.SearchAllSubDirectories, Nothing)
            Dim foundFile As String = My.Computer.FileSystem.GetFileInfo(File).Name
            If foundFile.Contains(TextBox1.Text) Then
                ListBox1.Items.Add(foundFile)
            End If
        Next
You can change "Desktop" to for example to "My Documents" or "My Pictures" for searching in other directories.

Re: Search function [help in VB-2010]

Posted: Tue Aug 14, 2012 1:07 pm
by CodenBoy
#DeveloperJacob , i used the code, but when i press the button it freeze, and i waited and nothing happened, any ideas? and btw i wrote in the textbox many things like "Filename" and "Filename.exe" non worked,

thx

Re: Search function [help in VB-2010]

Posted: Tue Aug 14, 2012 1:22 pm
by DeveloperJacob
CodenBoy wrote:
#DeveloperJacob , i used the code, but when i press the button it freeze, and i waited and nothing happened, any ideas? and btw i wrote in the textbox many things like "Filename" and "Filename.exe" non worked,

thx
With the code that I posted you can only search on your desktop. So if you don't have the file on your desktop it will freeze.
If you don't want your program freeze than you can use Try and Catch. And you can search a special directory by replacing
Code: Select all
My.Computer.FileSystem.SpecialDirectories.Desktop
with for example:
Code: Select all
"C:\Program Files"
.

Re: Search function [help in VB-2010]

Posted: Tue Aug 14, 2012 1:38 pm
by CodenBoy
Worked !!

Thaaaaaaaaaaanks #DeveloperJacob :)
thx bro, lol but it said filename.txt can u give me a code so the result in listbox be like "C:/mydocuments/files/subfiles/filename.txt" i dont want only filename.txt

any help?

thanks