Collection.Add

From Xojo Documentation

Method

Collection.Add(Value as Variant [,Key as String])

Supported for all project types and targets.

Adds Value as the last element of the collection.

Notes

If Key is provided, it may be used to refer to the element using the Item property. Key defaults to the empty string.

Sample Code

The following code creates a collection, populates it with both string and numeric values, and displays each element in TextFields or a Canvas control (The picture "lois" has been added to the project). Note that a collection is much like a database record.

Var c As New Collection
c.Add(1, "ID")
c.Add("Lois Lane", "Name")
c.Add("Reporter", "JobTitle")
c.Add(85000, "Salary")
c.Add(lois, "Picture")
TextField1.Value = c.Item("ID")
TextField2.Value = c.Item(2) // returns "Lois Lane"
TextField3.Value = c.Item("JobTitle")
TextField4.Value = c.Item("Salary")
Canvas1.Backdrop = c.Item("Picture")