search within a arraylist

J

James

I've open a file and read the file into arraylist. My text file contents are

a.txt=a.bat
b.txt=b.bat
c.txt=c.bat

i want to do a select case statement for filewatcher, if a.txt is created,
execute a.bat and etc etc I do not wish to hard-code all possible *.txt file
in my select case statements ...i thought of the script below. Pls advise
syntax

***********************************************
dim myitem as new arraylist
'open a file, and stored into array.
myitem.add(lines)

Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e As
System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created

select case e.name
'this is normally what i do
case "a.txt"
process.start("a.bat")

'say if c.txt file is created, how can i do a search into my
arraylist and then execute the batch file ?
'i do not wish to hard-code it for every text files.

case substr(myitems) or case instr(myitems) ...i m stuck here


end sub
 
C

Cor Ligthert [MVP]

James,

As I understand you well than you need an for index loop

Something as quickly typed.

\\\
dim i as integer
for i from 0 to myarraylist.lenght - 1
if myarraylist(i).ToString = myfileText then
exit for
next
dim whatIwantIsIn as string = myarraylist(i)
///

I hope this helps,

Cor
 
H

Herfried K. Wagner [MVP]

Cor Ligthert said:
As I understand you well than you need an for index loop

Something as quickly typed.

\\\
dim i as integer
for i from 0 to myarraylist.lenght - 1
if myarraylist(i).ToString = myfileText then
exit for
next
dim whatIwantIsIn as string = myarraylist(i)
///

Mhm... Why not use 'ArrayList.IndexOf' or 'ArrayList.BinarySearch' if the
list is already sorted?
 
C

Cor Ligthert [MVP]

Cor Ligthert said:
Mhm... Why not use 'ArrayList.IndexOf' or 'ArrayList.BinarySearch' if the
list is already sorted?
Because I all the time was thinking "There is a better way I know it",
however I have no brainconnector, so I could not find it.

:)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top