On Mar 25, 2007, at 10:32 AM, John Kubie wrote:
>
> On Mar 25, 2007, at 9:49 AM, Charles Yeomans wrote:
>
>> What is it that you find confusing about the Dictionary interface?
>
> The first awkwardness is the apparent necessity to test for the
> existence of a key before getting the key-value combination
> Next, the word "key" is not used when getting a value associated with
> a key.
>
> So
>
> if myDictionary.HasKey("name") then
> myvariable=mydictionary.value("name")
> end if
>
> is, I think, the correct code to get the value associated with the
> key "name".
Correct. I'm not sure what's awkward about this.
>
> If I were to try say what the second line is doing it is something
> like:
> "get the value associated with the key "name" from myDictionary and
> assign it to "myvariable".
>
> If the second line were:
> myvariable=mydictionary.KEY("name")
> it would make more sense to me.
But it would be wrong. mydictionary.value returns the value
associated to the key passed as the parameter. You described it
correctly above.
>
> There is also a wonderful function to get each key and value in a
> dictionary. (myVariant=myDictionary.values() and
> myVariant=myDictionary.keys()) I've used it several times and its
> great, but I have to look it each time. its not as simple as
>
> for i=0 ubound(myarray)
> next
>
> or
>
> for each element in myarray.
> next
It's as simple as
for i as Integer = 0 to d.Count - 1
dim theValue as Variant = d.Value(d.Key(i))
next
or
dim theValues() as Variant = d.Values
for i as Integer = 0 to UBound(theValues)
...
next
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>