The getdictionaryvalue( function returns the value of an item in the dictionary, given its key (see Data Dictionaries).
Parameters
This function has three parameters:dictionary – is the name of the field or variable that contains the dictionary (must contain binary data).
key – is the name of the key for the value you want to retrieve.
default – value to be used if the specified key does not exist in the dictionary. This may be any type of value, including an error (generated with the error( function. If this parameter is omitted, the default value will be empty text (""
).
Description
The getdictionaryvalue( function takes a key name and returns the corresponding value from dictionary collection. For example, suppose you created a dictionary and stored it in variable named mailto.
fileglobal mailto
mailto=initializedictionary("Address","3987 Olive","City","Tustin","State","CA","Zip","92841")
Later, you could use the getdictionaryvalue( function to retreive different values from the dictionary:
getdictionaryvalue(mailto,"Address") ☞ 3987 Olive
getdictionaryvalue(mailto,"City") ☞ Tustin
getdictionaryvalue(mailto,"State") ☞ CA
getdictionaryvalue(mailto,"Zip") ☞ 92841
Dictionary values are not restricted to text – you can use any type of data that Panorama supports, including numbers, dates, and binary data. This example includes both numbers and a date.
fileglobal InventoryItem
InventoryItem=initializedictionary("SKU",10445,"Description","Widget","Price",12.95",
"On Hand",687,"Last Order Date",date("12/17/2012"))
Later, you could use the getdictionaryvalue( function to retrieve different values from the dictionary:
getdictionaryvalue(InventoryItem,"SKU") ☞ 10445 (integer number)
getdictionaryvalue(InventoryItem,"Description") ☞ Widget (text)
getdictionaryvalue(InventoryItem,"Price") ☞ 12.95 (floating point number)
The examples above all assume the requested dictionary item actually exists. If it doesn’t, the statement will return empty text (""
). You can add a third parameter to specify a different default value, for example perhaps 0 for numeric dictionary items, or an error.
getdictionaryvalue(InventoryItem,"SKU",error("Unknown SKU"))
getdictionaryvalue(InventoryItem,"Description","UNKNOWN")
getdictionaryvalue(InventoryItem,"Price",0.0)
Advanced Note: If you used dictionaries in a previous version of Panorama (6.0 or earlier), the internal format used for dictionary collections has changed. The older version supported only MacOSRoman encoded text (no Unicode text), and did not support non text values. The new format lifts both of these restrictions. The old format is still supported in “read-only” mode for compatibility with existing databases. The data in an old format dictionary can still be accessed, but will automatically be converted to the new format if any changes are made.
See Also
History
Version | Status | Notes |
10.0 | Updated | Carried over from Panorama 6.0, but now may return numbers, dates or binary values in addition to text (depending on the dictionary contents). Also now has an optional default parameter. |