CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Location
    Mumbai, India
    Posts
    8

    Limitations of collections in VB

    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.



  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Limitations of collections in VB

    >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.


  3. #3
    Join Date
    Jun 1999
    Location
    Switzerland
    Posts
    58

    Re: Limitations of collections in VB

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured