PC Review


Reply
Thread Tools Rate Thread

How does Collection.Item search

 
 
=?Utf-8?B?UmF5IFBpeGxleQ==?=
Guest
Posts: n/a
 
      3rd Jul 2007
I recently moved from searching for data by arrays to collections, but found
that my macros now take 2 or 3 minute to process whereas when I was using
arrays it took 2 or 3 seconds to do the same work. But I don't want to go
back to arrays because indexing is always alway error prone.

I could add a binary search subroutine to speed up the search, but I was
wondering if that's already included in the Collections class. So, how does
Collections use the key to look up an item? Is it a simple sequential
search? If the adds are made with the keys presented alphabetically (less
work than debugging a binary search subroutine), will it respond better?
Thanks.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      3rd Jul 2007
I suspect it builds a hash table or index

This impression is reinforced from an Article on MSDN about working with
collections:

"This is because after deleting the first item, all items in the collection
are re-indexed so that what was the second item is now the first. "

A dictionary object from the scripting runtime may give you more of what you
need.

--
Regards,
Tom Ogilvy


"Ray Pixley" wrote:

> I recently moved from searching for data by arrays to collections, but found
> that my macros now take 2 or 3 minute to process whereas when I was using
> arrays it took 2 or 3 seconds to do the same work. But I don't want to go
> back to arrays because indexing is always alway error prone.
>
> I could add a binary search subroutine to speed up the search, but I was
> wondering if that's already included in the Collections class. So, how does
> Collections use the key to look up an item? Is it a simple sequential
> search? If the adds are made with the keys presented alphabetically (less
> work than debugging a binary search subroutine), will it respond better?
> Thanks.

 
Reply With Quote
 
=?Utf-8?B?UmF5IFBpeGxleQ==?=
Guest
Posts: n/a
 
      3rd Jul 2007
I saw the docs on the dictionary and tried it, specifically (copying from the
help file) :

Sub testDictionary()
Dim d 'Create a variable
Set d = CreateObject(Scripting.Dictionary)
d.add "a", "Athens" 'Add some keys and items
d.add "b", "Belgrade"
d.add "c", "Cairo"
End Sub

But when I try to execute (F8) it, I get "Compile Error: Variable not
Defined" and the word "Scripting" is not highlighted.

Suggestions?


"Tom Ogilvy" wrote:

> I suspect it builds a hash table or index
>
> This impression is reinforced from an Article on MSDN about working with
> collections:
>
> "This is because after deleting the first item, all items in the collection
> are re-indexed so that what was the second item is now the first. "
>
> A dictionary object from the scripting runtime may give you more of what you
> need.
>
> --
> Regards,
> Tom Ogilvy
>
>
> "Ray Pixley" wrote:
>
> > I recently moved from searching for data by arrays to collections, but found
> > that my macros now take 2 or 3 minute to process whereas when I was using
> > arrays it took 2 or 3 seconds to do the same work. But I don't want to go
> > back to arrays because indexing is always alway error prone.
> >
> > I could add a binary search subroutine to speed up the search, but I was
> > wondering if that's already included in the Collections class. So, how does
> > Collections use the key to look up an item? Is it a simple sequential
> > search? If the adds are made with the keys presented alphabetically (less
> > work than debugging a binary search subroutine), will it respond better?
> > Thanks.

 
Reply With Quote
 
=?Utf-8?B?UmF5IFBpeGxleQ==?=
Guest
Posts: n/a
 
      3rd Jul 2007
Er....Make that "Scripting" is highlighted.

"Tom Ogilvy" wrote:

> I suspect it builds a hash table or index
>
> This impression is reinforced from an Article on MSDN about working with
> collections:
>
> "This is because after deleting the first item, all items in the collection
> are re-indexed so that what was the second item is now the first. "
>
> A dictionary object from the scripting runtime may give you more of what you
> need.
>
> --
> Regards,
> Tom Ogilvy
>
>
> "Ray Pixley" wrote:
>
> > I recently moved from searching for data by arrays to collections, but found
> > that my macros now take 2 or 3 minute to process whereas when I was using
> > arrays it took 2 or 3 seconds to do the same work. But I don't want to go
> > back to arrays because indexing is always alway error prone.
> >
> > I could add a binary search subroutine to speed up the search, but I was
> > wondering if that's already included in the Collections class. So, how does
> > Collections use the key to look up an item? Is it a simple sequential
> > search? If the adds are made with the keys presented alphabetically (less
> > work than debugging a binary search subroutine), will it respond better?
> > Thanks.

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      3rd Jul 2007
Set D = CreateObject("Scripting.Dictionary")

It's just a string here, so surround it with double quotes.

Ray Pixley wrote:
>
> I saw the docs on the dictionary and tried it, specifically (copying from the
> help file) :
>
> Sub testDictionary()
> Dim d 'Create a variable
> Set d = CreateObject(Scripting.Dictionary)
> d.add "a", "Athens" 'Add some keys and items
> d.add "b", "Belgrade"
> d.add "c", "Cairo"
> End Sub
>
> But when I try to execute (F8) it, I get "Compile Error: Variable not
> Defined" and the word "Scripting" is not highlighted.
>
> Suggestions?
>
> "Tom Ogilvy" wrote:
>
> > I suspect it builds a hash table or index
> >
> > This impression is reinforced from an Article on MSDN about working with
> > collections:
> >
> > "This is because after deleting the first item, all items in the collection
> > are re-indexed so that what was the second item is now the first. "
> >
> > A dictionary object from the scripting runtime may give you more of what you
> > need.
> >
> > --
> > Regards,
> > Tom Ogilvy
> >
> >
> > "Ray Pixley" wrote:
> >
> > > I recently moved from searching for data by arrays to collections, but found
> > > that my macros now take 2 or 3 minute to process whereas when I was using
> > > arrays it took 2 or 3 seconds to do the same work. But I don't want to go
> > > back to arrays because indexing is always alway error prone.
> > >
> > > I could add a binary search subroutine to speed up the search, but I was
> > > wondering if that's already included in the Collections class. So, how does
> > > Collections use the key to look up an item? Is it a simple sequential
> > > search? If the adds are made with the keys presented alphabetically (less
> > > work than debugging a binary search subroutine), will it respond better?
> > > Thanks.


--

Dave Peterson
 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      4th Jul 2007
You may find this thread interesting. Whilst it for VB not VBA, the
underlying reasoning applies.

http://groups.google.co.uk/groups?as...=2007&safe=off

Note there are other implementations of a "Collection" available that will
may be faster than VBA/VB's built in one.

NickHK

"Ray Pixley" <(E-Mail Removed)> wrote in message
news:79CB9A33-8B69-4D56-8CB2-(E-Mail Removed)...
> I recently moved from searching for data by arrays to collections, but

found
> that my macros now take 2 or 3 minute to process whereas when I was using
> arrays it took 2 or 3 seconds to do the same work. But I don't want to go
> back to arrays because indexing is always alway error prone.
>
> I could add a binary search subroutine to speed up the search, but I was
> wondering if that's already included in the Collections class. So, how

does
> Collections use the key to look up an item? Is it a simple sequential
> search? If the adds are made with the keys presented alphabetically (less
> work than debugging a binary search subroutine), will it respond better?
> Thanks.



 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      4th Jul 2007
>> Set d = CreateObject(Scripting.Dictionary)


Just to let you know, that error in the Help system has been there for a
long time.

Set d = CreateObject("Scripting.Dictionary")

--
Dana DeLouis

"Ray Pixley" <(E-Mail Removed)> wrote in message
news:3CB65991-BAD3-436D-97E9-(E-Mail Removed)...
>I saw the docs on the dictionary and tried it, specifically (copying from
>the
> help file) :
>
> Sub testDictionary()
> Dim d 'Create a variable
> Set d = CreateObject(Scripting.Dictionary)
> d.add "a", "Athens" 'Add some keys and items
> d.add "b", "Belgrade"
> d.add "c", "Cairo"
> End Sub
>
> But when I try to execute (F8) it, I get "Compile Error: Variable not
> Defined" and the word "Scripting" is not highlighted.
>
> Suggestions?
>
>
> "Tom Ogilvy" wrote:
>
>> I suspect it builds a hash table or index
>>
>> This impression is reinforced from an Article on MSDN about working with
>> collections:
>>
>> "This is because after deleting the first item, all items in the
>> collection
>> are re-indexed so that what was the second item is now the first. "
>>
>> A dictionary object from the scripting runtime may give you more of what
>> you
>> need.
>>
>> --
>> Regards,
>> Tom Ogilvy
>>
>>
>> "Ray Pixley" wrote:
>>
>> > I recently moved from searching for data by arrays to collections, but
>> > found
>> > that my macros now take 2 or 3 minute to process whereas when I was
>> > using
>> > arrays it took 2 or 3 seconds to do the same work. But I don't want to
>> > go
>> > back to arrays because indexing is always alway error prone.
>> >
>> > I could add a binary search subroutine to speed up the search, but I
>> > was
>> > wondering if that's already included in the Collections class. So, how
>> > does
>> > Collections use the key to look up an item? Is it a simple sequential
>> > search? If the adds are made with the keys presented alphabetically
>> > (less
>> > work than debugging a binary search subroutine), will it respond
>> > better?
>> > Thanks.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen Microsoft ASP .NET 1 18th May 2007 10:24 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
key/value collection that allows key string to be updated and retains collection item entry order dx Microsoft Dot NET Framework 2 25th Sep 2004 05:51 PM
Item Collection Editor doesn't preserve collection Andrés Giraldo Microsoft ASP .NET 2 25th Mar 2004 08:38 PM
Custom collection: how to find item in collection using custom indexer panik Microsoft C# .NET 0 21st Aug 2003 09:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:55 PM.