From: greg on
Hello, here is an easy one.


I have a collection of file names.
I would like to check if a name exists, before adding it in.

Now I currently do not have a key. But there are 2 ways I can think of
codeing this.

put the item as the key also
Col.add "file1.doc", "file1.doc"
and then just checking the key

or
creating a loop. and looping through the collection. checking for the
file.


Is one better than the other?
One throws an error. the other could take longer.

or is there some other way of doing this?
thanks


From: Jan Hyde (VB MVP) on
"greg" <iuouh(a)ghfhg.com>'s wild thoughts were released on
Thu, 17 Jul 2008 10:59:31 -0500 bearing the following fruit:

>Hello, here is an easy one.
>
>
>I have a collection of file names.
>I would like to check if a name exists, before adding it in.
>
>Now I currently do not have a key. But there are 2 ways I can think of
>codeing this.
>
>put the item as the key also
>Col.add "file1.doc", "file1.doc"
>and then just checking the key
>
>or
>creating a loop. and looping through the collection. checking for the
>file.
>
>
>Is one better than the other?
>One throws an error. the other could take longer.
>
>or is there some other way of doing this?
>thanks

I'd probably go for the adding it as a key, however, where
is the list coming from?

--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde
From: Ivar on
I wouldn't use the file name as the key, You might have a file called
123.doc, or you might have the same file name in two locations. A
For..Each..Next to loop is much faster than a For..Next loop when working
with collections.

Ivar



From: Bob Butler on

"Ivar" <ivar.ekstromer000(a)ntlworld.com> wrote in message
news:PmKfk.3229$uS4.2781(a)newsfe17.ams2...
>I wouldn't use the file name as the key, You might have a file called
>123.doc,

You can use something like
c.add thename,"|K|" & thename

> or you might have the same file name in two locations.

If so then you use the full path instead of just the name

I'd go with the indexed collection and trap the error

From: MP on

"greg" <iuouh(a)ghfhg.com> wrote in message
news:udiWrXC6IHA.2336(a)TK2MSFTNGP03.phx.gbl...
> Hello, here is an easy one.
>
>
> I have a collection of file names.
> I would like to check if a name exists, before adding it in.
>
> Now I currently do not have a key. But there are 2 ways I can think of
> codeing this.
>
> put the item as the key also
> Col.add "file1.doc", "file1.doc"
> and then just checking the key
>
> or
> creating a loop. and looping through the collection. checking for the
> file.
>
>
> Is one better than the other?
> One throws an error. the other could take longer.
>
> or is there some other way of doing this?
> thanks
>
>

my favorite is dhSortedDictionary.dll by Olaf Schmidt
http://www.thecommon.net/2.html

his cSortedDictionary has an .Exists method (and lots more) and is faster
and better in every way than builtin collections or other options (imho)
hth
mark