New topic: Dictionary, question
<http://forums.realsoftware.com/viewtopic.php?t=46142> Page 1 of 1 [ 5 posts ] Previous topic | Next topic Author Message jas1931 Post subject: Dictionary, questionPosted: Wed Dec 05, 2012 11:04 am Joined: Tue May 31, 2011 9:16 am Posts: 96 Location: Chapin, SC I have look at the RS documentation for Dictionary and the examples that come with RS. I still don't understand how to use it. To me I think of a dictionary as a list word (phases) and you use as a key to find another word or phase. However the examples I find don't appear, to me, to do that. What am I missing? Could someone point me to some example and an explanation. _________________ Jim Smith http://www.rvcarelogbook.com Mac OSX 10.7, RS 2012R1.2 Top DaveS Post subject: Re: Dictionary, questionPosted: Wed Dec 05, 2012 11:23 am Joined: Sun Aug 05, 2007 10:46 am Posts: 4325 Location: San Diego, CA That is exactly what a dictionary is... a collection of objects (text, classes, any data structure) that is entereed and retreieved by the use of a unique key. _________________ Dave Sisemore MacPro, OSX Lion 10.7.4 RB2012r1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top charonn0 Post subject: Re: Dictionary, questionPosted: Wed Dec 05, 2012 1:18 pm Joined: Mon Apr 02, 2007 2:08 am Posts: 1024 Location: San Francisco, CA, USA A Dictionary is a data structure that allows you to "look up" values within it, though I'm sure the name has confused more than a few RB converts. A Dictionary in RB can be thought of as a collection of Key=Value pairs. The advantage of the Dictionary class (over, say, an array) is that finding a key/value will take the same amount of time no matter how many keys there are in the dictionary and the values can be of any type, even another Dictionary or Nil. _________________ Boredom Software Top ktekinay Post subject: Re: Dictionary, questionPosted: Wed Dec 05, 2012 1:29 pm Joined: Mon Feb 05, 2007 5:21 pm Posts: 284 Location: New York, NY This of it as an in-memory database with one value and one, unique search key. The keys can be anything (although it's usually just text), and the values can be anything, or can be nil. These are all valid: dim d as new Dictionary d.Value( "this" ) = "that" d.Value( "that" ) = 3 d.Value( someClassInstance ) = nil d.Value( "Embedded Dictionary" ) = new Dictionary dim arr() as string = Array( "a", "b", "c" ) d.Value( "list" ) = arr You'd use it anywhere you have to associate some data with a key. For example, it's a great place to keep preferences, or return a variety of values from a method: Function Info(m As SomeObject) As Dictionary dim d as new Dictionary d.Value( "Length" ) = m.Length d.Value( "Width" ) = m.Width d.Value( "Name" ) = GetTheName( m ) // etc. return d end Function You can also take advantage of the fact that keys must be unique to remove duplicates from arrays: Function RemoveDups(arr() As String) As String() dim d as new Dictionary for each s as string in arr d.Value( s ) = nil next dim newArr() as string for each v as Variant in d.Keys newArr.Append v next return newArr // Will be unique End Function This is just a partial list of what you can do with a Dictionary. _________________ Kem Tekinay MacTechnologies Consulting http://www.mactechnologies.com/ Need to develop, test, and refine regular expressions? Try RegExRX. Top jas1931 Post subject: Re: Dictionary, questionPosted: Wed Dec 05, 2012 7:05 pm Joined: Tue May 31, 2011 9:16 am Posts: 96 Location: Chapin, SC I think I got it now. Thanks. _________________ Jim Smith http://www.rvcarelogbook.com Mac OSX 10.7, RS 2012R1.2 Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 5 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
