comp • gb • collection

Collection (gb)

Implements an hash table whose keys are String and values are Variant.

NULL is used when nothing is associated with a given key. Consequently, associating NULL with a key is the same thing as removing it from the collection.

The size of the internal hash table grows dynamically as data is inserted.

This class is
Creates a new collection.
creatable
.
This class acts like a
Returns the value associated with Key.
read
/
Associates a value with Key.
write
array.
This class is
Enumerates each value stored in the collection.
enumerable
with the FOR EACH keyword.

Properties

Methods
Returns the number of elements stored in the collection.
Count  
Return or set the collection default value that is returned when no value is associated with a key.
Default  
Returns the key of the first element of the collection, or NULL if the collection is void.
First  
Returns the key of the last read or last enumerated element.
Key  
Returns the key of the last element of the collection, or NULL if the collection is void.
Last  
Returns the number of elements stored in the collection.
Length  
Adds an element to the collection.
Add  
Clears the collection.
Clear  
Returns a copy of the collection.
Copy  
Returns if something is associated with this key in the collection.
Exist  
Removes an element from the collection.
Remove  

Example

Public Sub Main()

  Dim cAbbr2Weekday As Collection = ["mo": "Monday", "tu": "Tuesday", "we": "Wednesday", "th": "Thursday", "fr": "Friday", "sa": "Saturday", "su": "Sunday"]
  Dim cCopy As Collection
  Dim sAbbr As String
  
  ' To access the data
  Print cAbbr2Weekday["fr"]
  
  ' Print mapping key to value
  For Each sAbbr In cAbbr2Weekday
    Print cAbbr2Weekday.Key & " --> " & sAbbr
  Next

  ' Lenght/Count return both 7
  Print cAbbr2Weekday.Count
  Print cAbbr2Weekday.Length

  ' Add element and remove it again
  cAbbr2Weekday.Add("sat", "Saturday")
  cAbbr2Weekday.Remove("sat")
  
  ' Test if a key is present
  Print cAbbr2Weekday.Exist("we")
  
  ' Make a copy and clear the original collection
  cCopy = cAbbr2Weekday.Copy()
  cAbbr2Weekday.Clear()

End