Collection

Collection (gb)

This class 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 creatable . This class acts like a read / write array. This class is enumerable with the FOR EACH keyword.
Properties
Count Returns the number of elements stored in the collection.
Default
Since 3.9
Return or set the collection default value that is returned when no value is associated with a key.
Empty
Since 3.18
Return if the collection is empty.
First
Since 3.11
Returns the key of the first element inserted in the collection, or NULL if the collection is void.
Key Returns the key of the last read or last enumerated element.
Keys
Since 3.17
Return a string array of all collection keys.
Last
Since 3.11
Returns the key of the last element inserted in the collection, or NULL if the collection is void.
Length Returns the number of elements stored in the collection.
ReadOnly
Since 3.20
Return or set if the collection contents is read-only.
Methods
Add Adds an element to the collection.
Clear Clears the collection.
Copy Returns a copy of the collection.
Equals
Since 3.20
Returns if Collection is equals to the current collection.
Exist Returns if something is associated with this key in the collection.
Insert
Since 3.20
Insert the contents of Collection into the current collection.
Remove Removes an element from the collection.

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("Saturday", "sat")
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

AltStyle によって変換されたページ (->オリジナル) /