Results 1 to 7 of 7

Thread: VB6 a simple wrapper for the VBA.Collection with (much) faster Indexed-Access

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    VB6 a simple wrapper for the VBA.Collection with (much) faster Indexed-Access

    The title says it all - this is a simple Collection-Wrapper which can act as a compatible
    Replacement for the VBA.Collection - the fast Hash-Access of the VBA.Collection is used further -
    but all the disadvantages with indexed access are avoided for the most typical use-cases.

    At this occasion there were also some other enhancements made as:
    - an Exists Method to check for Keys
    - a RemoveAll-method
    - can hand out Value- and Key-Arrays in appropriate Variant- or String-Arrays (with userdefinable LBound)
    - in addition to the compatible Item-Method we have ItemByIndex and KeyByIndex too
    - The unnerving behaviour to not allow Add(..., BeforeIndex) with an Index at constantly 1 (in case of Count=0) is gone

    It should be also possible, to implement the Item-property also in Write-Direction (with Property Let/Set),
    but I leave that for interested colleagues to explore - currently the internally used Collection-Instance-Types,
    which were pointed out to me in this thread for the first time (structs posted by jbarnett74 - then refined with a few more
    explanations by Bonnie West) - these Structures are currently only used within this wrapper in "safe-read-only-fashion".

    Those who try themselves at implementing Write-Access for the Values over the Item-Property,
    should test this accordingly (back and forward), because these Structs contain quite a few
    "still unknown members", which partly are used for the Hashing-functionality of the VB-Collection,
    but some of them could also store additional information, which is related to the Value-member
    of the Element-Struct - so changing the Value-Member is alluringly simple - since it seems easily
    accessible also for the Write-Direction - but one doesn't know yet, if changing its Value requires
    also changes in a few so far unknown members (which the Add-Method of the VB-Collection might
    automatically ensure under the covers).

    So, as the implementation comes currently - it is "playing things safe" - no real risk in using it, especially
    when you compile it into a dedicated ActiveX-Dll-Binary, to give the Class more IDE-safety with regards
    to cleanup, even when the Stop-Button was pressed in the IDE (it needs to run over its Class_Terminate-
    Event to clear things up properly).

    Ok, so here is the Implementation- and Demo-Code (with a small performance-test):
    CollectionEx.zip

    And here the appropriate ScreenShot:


    An additional advice for those who plan to compile it into an ActiveX-Dll-Binary,
    all extended native Compiler-Options are allowed *aside* from the "Aliasing-Option"
    (which should remain unchecked in this case of SafeArray-Pointer-usage).

    Edit: Please take note that the Class in the above Demo-Zip still contains a Copy&Replace-Bug,
    as pointed out by Elroy in post #5 - I will not re-upload the Zip, since it's easy enough to find and fix IMO.


    Olaf
    Last edited by Schmidt; Aug 30th, 2016 at 10:03 PM.

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