How To: Work with Name Dictionaries [SCRIPT]


The script in this document shows you how to work with Name Dictionaries?


The following script shows how you can work with Name Dictionaries

'--- Name Dictionaries use the name of the object (set with SetNme())
'--- as the Key and the Object itself becomes the Value.
'--- Make a name dictionary with a hashing table of 5
aNameDictionary = NameDictionary.make(5)

'--- Create some dummy key/value pairs and add them to the dictionary
astr1 = "Value 1"
astr1.setname("Key 1")

astr2 = "Value 2"
astr2.setname("Key 2")

'--- Get the list of keys to loop with
theKeys = aNameDictionary.returnkeys
'--- Presend the keylist to verify
msgbox.listasstring(theKeys,"The Dictionary Keys are:","Key List")

'--- Getting Info from the dictionary
'--- The Looping approach to dealing with elements
'--- Query each element by key - looping with each element
for each aKey in thekeys
aValue = aNameDictionary.get(aKey)
msgbox.info("The Key:" +TAB +TAB+ aKey +nl+ "The Value:"+TAB+
aValue.asstring, "The Key/Value Pairs:")

'--- The direct approach to getting values associated with the key
myValue1 = aNameDictionary.get("Key 1")
msgbox.info(myValue1.asstring,"Key 1 Value is:")
myValue2 = aNameDictionary.get("Key 2")
msgbox.info(myValue2.asstring,"Key 2 Value is:")

'--- End of Script