COLLECTION.SET Function

Syntax

V Set(A key,A value)

<COLLECTION>.SET( Key as C, Data as A )

<COLLECTION>.SET( Key as C, Data as P )

<COLLECTION>.SET( Key as D, Data as A )

<COLLECTION>.SET( Key as N, Data as A )

Arguments

key

A value (character, numeric or date) that uniquely identifies an element in a collection.

value

The data to be saved into the collection element.

Description

Set/Add element to collection.

Discussion

The <COLLECTION>.SET() method sets the Data for the specified Key in the specified collection. If the collection does not have the specified Key, then the Key is added, and the Data is associated with it. If the Key already exists, then the data value for that key is changed.

Example

dim mycollection as u
mycollection.SET("FJ","Fred Jones")
mycollection.SET("BB","Bryan Boyd")
mycollection.SET("KL","Kim Lee")
mycollection.SET("KB","Karen Boyd")
mycollection.SET("EL","Erica Loyd")
x = mycollection.enum_all()
? x
= "FJ
BB
KL
KB
EL
"

The "value" that you assign to a collection entry does not have to be a scalar. It can be a dot variable with multiple children, as shown in the following example.

dim a as P
dim b as P
dim u as U
a.name = "Fred"
a.city = "Boston"
a.company = "Alpha"
b.name = "Ed"
b.city = "Nashua"
b.company = "Beta"
u.set("Fred", a)
u.set("Ed", b)
? u.get("Ed").company
= "Beta"
? u.get("Fred").city
= "Boston"

Here is an example where the collection elements are numbers.

dim mycollection as u
dim k as N
dim i as N = 1
dim keyval as C
dim currentval as N
mycollection.SET("One",1)
mycollection.SET("Two",2)
mycollection.SET("Three",3)
mycollection.SET("Four",4)
mycollection.SET("Five",5)
k = mycollection.size()
keyval = mycollection.first()
currentval = mycollection.get(keyval)
mycollection.set(keyval, currentval)
ui_msg_box("","Key = " + keyval + " Data = " + mycollection.get(keyval))
while (i < k)
    keyval = mycollection.next(keyval)
    currentval = mycollection.get(keyval)
    mycollection.set(keyval, currentval)
    i = i + 1
    ui_msg_box("","Key = " + keyval + " Data = " + mycollection.get(keyval))
end while

See Also