Search function [help in VB-2010]

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
7 posts Page 1 of 1
Contributors
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

Search function [help in VB-2010]
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
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Search function [help in VB-2010]
Filip
How would you like to display results?
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

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
User avatar
DeveloperJacob
VIP - Donator
VIP - Donator
Posts: 87
Joined: Sun May 27, 2012 12:40 pm

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.
Image
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

#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
User avatar
DeveloperJacob
VIP - Donator
VIP - Donator
Posts: 87
Joined: Sun May 27, 2012 12:40 pm

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"
.
Image
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

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
7 posts Page 1 of 1
Return to “Coding Help & Support”