DUMB question about IndexOf

  • Thread starter Thread starter Nonee
  • Start date Start date
N

Nonee

Ok ok... I have been staring at this for a generation or so now and it
is not working. And it is something really simple too. I have a
listbox of mp3s (flbMp3s). I have a textbox (txtSearch). I have the
directory of the mp3s (System.IO.Directory.GetFiles). I want to
search the directory from the text in the textbox, adding to the
listbox if there is a match. I have tried
file.IndexOf(txtSearch.Text), file.Contains(txtSearch.Text), and even
InStr(file, txtSearch.Text).

What am I missing? Is there an easier way to do this? I just want to
search for specific artists, songs, etc. This isn't hard... WHAT IS
GOING ON!!! heh.


Thanks,

Josh

Dim file As String
Dim mp3sPath As String = flbMp3s.Path

If (txtSearch.Text <> "") Then
'clear listbox

flbMp3s.Items.Clear()
'loading each file in working direcrtory of application
For Each file In
System.IO.Directory.GetFiles(flbMp3s.Path)
'storing the filename into listbox items collection
If (InStr(file, txtSearch.Text) > 1) Then
flbMp3s.Items.Add(file)
End If
Next
End If
 
Nonee said:
Ok ok... I have been staring at this for a generation or so now and
it is not working. And it is something really simple too. I have a
listbox of mp3s (flbMp3s). I have a textbox (txtSearch). I have
the directory of the mp3s (System.IO.Directory.GetFiles). I want to
search the directory from the text in the textbox, adding to the
listbox if there is a match. I have tried
file.IndexOf(txtSearch.Text), file.Contains(txtSearch.Text), and
even InStr(file, txtSearch.Text).

What am I missing? Is there an easier way to do this? I just want
to search for specific artists, songs, etc. This isn't hard... WHAT
IS GOING ON!!! heh.


Thanks,

Josh

Dim file As String
Dim mp3sPath As String = flbMp3s.Path

If (txtSearch.Text <> "") Then
'clear listbox

flbMp3s.Items.Clear()
'loading each file in working direcrtory of application
For Each file In
System.IO.Directory.GetFiles(flbMp3s.Path)
'storing the filename into listbox items collection
If (InStr(file, txtSearch.Text) > 1) Then
flbMp3s.Items.Add(file)
End If
Next
End If


Maybe it's because an "A" is not an "a"?


Dim file As String
Dim mp3sPath As String = flbMp3s.Path
-> dim value as string = txtearch.text

-> If value.length > 0 Then
-> value = value.tolower
'clear listbox

flbMp3s.Items.Clear()
'loading each file in working direcrtory of application
For Each file In System.IO.Directory.GetFiles(flbMp3s.Path)
'storing the filename into listbox items collection
-> If file.TOLOWER.indexof(value) > -1 Then
flbMp3s.Items.Add(file)
End If
Next
End If


Don't know if this is the problem.


Armin
 
Either this is too easy or I completely missed your point...

Dim myPattern As String = "*christina*.mp3"
Dim myFolder As String = "C:\MyMusic"
For Each myFile As IO.FileInfo In (New
IO.DirectoryInfo(myFolder)).GetFiles(myPattern)
'Fill listbox...
Next
 
Back
Top