Home All Groups Group Topic Archive Search About

search within a arraylist

Author
20 Jan 2006 2:53 AM
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

Author
20 Jan 2006 6:48 AM
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
Author
20 Jan 2006 3:17 PM
Herfried K. Wagner [MVP]
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
> 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?

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
20 Jan 2006 4:01 PM
Cor Ligthert [MVP]
Show quote Hide quote
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
>> 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?
>
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