Click to See Complete Forum and Search --> : Limitations of collections in VB


Sanjay Adlakhiya
August 16th, 1999, 02:57 PM
Is it true that a collection in Visual Basic can only have a length of 256 and no more?
How do we overcome this limitation?

I want to store objects (about 2500 in number). What is the easiest & fastest way to do it ? Does Visual Basic offer workaround?

Is there any way I could emulate a collection object using an array of objects internally inside a class exposing the same methods & properties as those exposed by a collection? I have already used a collection in my code & want to disturb the code already written as least as possible.

Please help me ASAP.
Thanks.
Sanjay.

Lothar Haensler
August 17th, 1999, 01:40 AM
>Is it true that a collection in Visual Basic can only have a length of 256 and no more?
No, it's not true.
>What is the easiest & fastest way to do it ? Does Visual Basic offer workaround?
in my experience the Dictionary object that comes with VB 6 is much faster than a collection and it offers more functionality.

Jan Businger
August 17th, 1999, 03:23 AM
Hi,
I agree with Lothar in that you should use dictionary objects instead of collections.
Please note the following:
All exmaples in VB6 manuals are taken as is from VBScript documentation and therefore use a <CreateObject> function to create the dictionary.
While this code works, you should avoid this:
CreateObject is twice as slow and there is another reason which I cannot explain in full.

You create a dictionary object as you do any object.
..Dim dict as new Scripting.Dictionary..

In all cases, note that the <Scripting> prefix is optional but it is suggested that you use it in case your <References> dialog box includes other external libraries that happen to expose a Dictionary object.

You add an item using the "add" method as with collections. But the ORDER of the arguments is reveresed (first the key, then the item's value)

Dictionary objects are more flexible than Collections objects. Their only missing feature is the ability to address items by their indices.


Remarks taken from "Programming Visual Basic60" by Francesco Balena

Good Luck

Jan Businger