VB.Net, Multiple search parameters

Hi Experts

I am searching through a list with multiple search parameters with this

For each f in FileList
If  f=  FileName1 Or f = filename 2 Or  f = filename3 Then
Do stuff
End if

But now I have a situation whereby the user may choose as many as ten different filenames to search
and the number of filenames to search could change every time the search is run.

What is the correct way to handle this?

Many thanks in advance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
Please provide more details. What type of object is FileList? Are the filenames (filename1-3) you are comparing coming from a list or an array?

General idea: If you use a generic list object (List<your type>) you can use the Contains method to find a value in the list. So your loop could be changed to something like:
For each f in FileList
 If  myListofFilestoSearchfor.Contains(f.ToString()) Then
 Do stuff
 End if

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jacques Bourgeois (James Burger)PresidentCommented:
Be careful with Contains.

If the user looks for "File1", it will also return File12, File190, File1999_02-05, MyFile12,MiniFile1To2.

Contains is not the right way to go if you are looking for a specific file name.

If this is your case, and if the number of files changes, your best bet would be to use a collection for your filenames:

            Dim FileNames As Collections.Generic.List(Of String)

            For Each f In FileList
                  For Each n In FileNames
                        If f = n Then
                              'Do stuff
                        End If
PNRTAuthor Commented:
As usual, this was a very detailed and more accurate answer.  Many thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.