COLLECTION.GET Function

Syntax

Data as A = <COLLECTION>.GET( Key as A )[. Child_Name as C ])

Data as A = <COLLECTION>.GET( Key as D )

Data as A = <COLLECTION>.GET( Key as N )

Arguments

keyAny Type Date Numeric

Any type

Child_NameCharacter

The name of a child variable.

Returns

DataAny Type

Returns the value for the specified Key. If the key does not exist, the type of the returned value will be "Z".

Description

Get the value for an element from the collection.

Discussion

The <COLLECTION>.GET() method returns the Data associated with a specified Key.

Trailing spaces in the specified key are considered part of the key and are not trimmed.

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")
? mycollection.get("BB")
= "Bryan Boyd"
' The key is not case sensitive
? mycollection.GET("bb")
= "Bryan Boyd"
? mycollection.get("b")
= <No data returned>
x = mycollection.get("somekeythatdoesnotexist") ?typeof(x) ="Z"

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"

If the data in a field is a logical field that allows NULL values, <COLLECTION>.GET() can return up to three possible values: .t., .f., or NULL. This primarily applies to collections populated from a DBF table using the from_table() method. For example:

dim collection as U
t = table.open("products")
filename = t.filename_get()
collection.from_table(filename,"product_id","discontinued")
t.close()

? collection.get("122")
= .F.

? collection.get("123")
= .T.

? collection.get("124")
= NULL

See Also