[ ] use "dict.inc" [ ] [ ] [ ] // these are for the simpler section .. section a [+] window Dictionary adict [ ] [+] window Dictionary bdict [ ] [+] window Dictionary edict [ ] [ ] [ ] [ ] // these are for the more advanced section .. section b [+] window Dictionary lge_dict [ ] [+] window Dictionary copy_dict [ ] [ ] [ ] [+] window Dictionary potpurri [ ] [ ] window Dictionary smalldict [ ] [ ] [ ] // let us test out the dictionaries [-] testcase dict_test () appstate none [ ] [ ] // WP stands for working path this was set up to write to diskette [ ] // be my guest and tailor it to what you want [ ] // STRING WP = "a:\" [ ] [ ] //Please change this to your own preffered drive letter + directory [ ] STRING WP = "c:\" [ ] [ ] [ ] // simple assignment statements [ ] adict.Assn("key1","beauty exists") [ ] adict.Assn("key2","Another Day in the life of Joe Mama.") [ ] adict.Assn("key3","This is too foul") [ ] adict.Assn("key3","This is truly sublime") [ ] [ ] // ldict is the state variable list of ANYTYPE [ ] // that stores all this information in key,value pairs [ ] print(adict.ldict) [ ] [ ] bdict.Assn("key1a","beautya exists") [ ] bdict.Assn("key2a","Anothera Day in the life of Joe Mama.") [ ] bdict.Assn("key3","Thisa is too foul") [ ] bdict.Assn("key3","Thisa is truly sublime") [ ] print(bdict.ldict) [ ] [ ] [ ] // examples of getting at the values via the keys [ ] print("let us acess some of the values through the keys") [ ] STRING tmp = adict.GetValue("key1") [ ] print(tmp) [ ] print(adict.GetValue("key3")) [ ] print(bdict.GetValue("key3")) [ ] print(bdict.GetValue("key2a")) [ ] [ ] // an example of merging two dictionaries into [ ] // the host dictionary "adict" [ ] adict.Merge(bdict) [ ] [ ] // now let us store [ ] adict.StoreToFile("{WP}adict.txt") [ ] adict.PrintDict("dictionary adict contains") [ ] [ ] print("edict before initialization is {edict.ldict}") [ ] edict.InitFromFile("{WP}adict.txt") [ ] print("edict after initialization from {WP}adict.txt is {edict.ldict}") [ ] [ ] print("lets add a few more keys ..") [ ] edict.Assn("rick","cool key man") [ ] edict.Assn("rickw","rick is too cool") [ ] [ ] edict.Assn("rick_is","a pin head") [ ] edict.PrintDict("edict contents") [ ] [ ] // we cannot go around saying rick is a pinhead! [ ] edict.Delete("rick_is") [ ] edict.PrintDict("edict contents") [ ] [ ] [ ] print("let us save the contents of edict to file {WP}edict.txt") [ ] edict.StoreToFile("{WP}edict.txt") [ ] [ ] [ ] // lets stress test the dictionary class to see if it can handle this [ ] INTEGER i = 0 [+] for i = 1 to 3000 [ ] lge_dict.Assn("key"+Str(i),"value"+Str(i)) [ ] [ ] lge_dict.StoreToFile("{WP}lge_dict.txt") [ ] [ ] //print out samples of the dictionary [+] for i = 1 to 10 [ ] print(lge_dict.GetValue("key"+Str(i))) [ ] [+] for i = 100 to 110 [ ] print(lge_dict.GetValue("key"+Str(i))) [ ] [+] for i = 990 to 1000 [ ] print(lge_dict.GetValue("key"+Str(i))) [ ] [ ] copy_dict.InitFromFile("{WP}lge_dict.txt") [-] for i = 1 to 10 [ ] print(copy_dict.GetValue("key"+Str(i))) [ ] [-] for i = 100 to 110 [ ] print(copy_dict.GetValue("key"+Str(i))) [ ] [-] for i = 990 to 1000 [ ] print(copy_dict.GetValue("key"+Str(i))) [ ] [ ] [ ] // ok lets set up a small dictionary [ ] smalldict.Assn('float_lst',{1.0,2.0,3.0,4.0}) [ ] smalldict.Assn('int_lst',{1,3,2,4,5,6,7}) [ ] ARRAY [2][2] OF ANYTYPE airy [-] airy = {...} [ ] {19,20} [ ] {"moe","larry"} [ ] [ ] [ ] smalldict.Assn('array',airy) [ ] [ ] print(smalldict.ldict) [ ] [ ] // lets mix it up [ ] // note that I can store a dictionary as a value to a key [ ] potpurri.Assn("mixdict",smalldict.ldict) [ ] potpurri.Assn("rickw","is too cool") [ ] potpurri.Assn("AlvinaB","is a sniper .. watch out") [ ] potpurri.Assn("RaisaZ","is a QAP whiz") [ ] potpurri.Assn("Martin",{"Do not trust anyone over",38,"especially","Mr Rick"}) [ ] potpurri.StoreToFile("{WP}popurri.txt") [ ] [ ] [ ] // ok here are a few more features let's look at the Merge [ ] // method which will merge two dictionaries together into the [ ] // host dictionary [ ] // [ ] // In this example the host dictionary is adict and the dictionary [ ] // we will merge into adict is potpurri [ ] print("adict before merge of potpurri {adict.ldict}") [ ] adict.Merge(potpurri) [ ] print("adict after merge of potpurri {adict.ldict}") [ ] [ ] // ok watch this .. even though a merge would do "effectively the same thing" [ ] // this assignment statement will "clobber" old values you may not want [ ] // [ ] // ldict is the state variable which contains the [ ] // dictionary you can always acess it dicrectly as [ ] // it is an implied public variable [ ] print("adict before assignment of smalldict {adict.ldict}") [ ] adict.ldict = smalldict.ldict [ ] print("WHAMMO adict after assignment of smalldict {adict.ldict}") [ ] [ ] // ok let's really zap adict .. were gonna run down it's ldict [ ] // were gonna make it squek!! [+] adict.ldict = {...} [ ] [ ] print(" did we really zap it's little ldict adict.ldict = {adict.ldict}") [ ] [ ] [ ] // finally lets assign just the keyed dictionary in potpurri .. the [ ] // mixdict stored off key mixdict to adict .. now we could merge .. but [ ] // let's just zap the bastid! [ ] adict.ldict = potpurri.GetValue("mixdict") [ ] print("adict after assignment of the mixdict in potpurri {adict.ldict}") [ ] [ ]