Function Hash Table Class

AddOrUpdate

Add a new definition ( Key and Item pair) into the hash table or update an existing Key and Item pair. Inserting an Item with the same Key as another Item in the table causes the previous Item to be overwritten.

Signature (Visual Basic / VBA)

Public Function AddOrUpdate( _
      ByVal vKey As Variant _
    , ByVal vItem As Variant _
    ) As Boolean

Code Example

    Assuming
       Dim htTemp As New HashTable
    for example
       htTemp.AddOrUpdate "FunctionName", 23
       htTemp.AddOrUpdate "FunctionName", 24
    leaves
       htTemp.Count = 1

Parameters

Parameter Description
vKey The string or numeric identifier associated with the Item vItem.
vItem Item that will inserted into the hash table along with its identifier (or new Item that will replace the previous Item associated with Key ). vItem can be any type of Variant value (vbString, numeric, vbDate, vbObject, vbArray, etc.).

Return Value

Method returns True if new Key & Item pair was Added, and returns False if existing Key was Updated with new Item .

Notes & Version History

v1.3 BugFix This method has been fixed to support the storage of Object and DataObject type Items .
v1.5 BugFix Corrected a bug that caused this method to not work correctly in many cases.
v1.5 Change AddOrUpdate now returns True if the Key & Item pair was Added, and it returns False if an existing Key was Updated with a new Item .