Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Update item value in a dictionary object?

3 views
Skip to first unread message

JJ

unread,
Dec 25, 2006, 5:00:29 AM12/25/06
to
If you want to change the 'item' value of an existing key/item pair in
a dictionary, can it be done, or is it necessary to do a Remove
followed by an Add?

Set mydict = CreateObject("Scripting.Dictionary")

' Append to existing item value using Remove/Add
If mydict.Exists(key) Then
temp = mydict(key) & ";" & item
mydict.Remove(key)
mydict.Add key, temp
Else
mydict.Add key, item
End If

' Or is there a simpler way?
If mydict.Exists(key) Then
mydict(key) = mydict(key) & ";" & item
Else
mydict.Add key, item
End If

urkec

unread,
Dec 25, 2006, 11:39:01 AM12/25/06
to
if you want to change the item for an existing key to a new value use
mydict.item and specify the key you want

mydict.item(key) = newValue

--
urkec

JJ

unread,
Dec 25, 2006, 6:49:24 PM12/25/06
to
urkec wrote:
>
> if you want to change the item for an existing key to a new value use
> mydict.item and specify the key you want
>
> mydict.item(key) = newValue

Thanks. What then is the difference between the following?

mydict.Item(key)

mydict(key)

They both appear to evaluate to the value of item in a key/item pair.

urkec

unread,
Dec 26, 2006, 2:38:01 PM12/26/06
to
Who can tell? Maybe the Item is the default property of the Dictionary object
--
urkec

Anthony Jones

unread,
Dec 26, 2006, 4:11:21 PM12/26/06
to

"urkec" <ur...@discussions.microsoft.com> wrote in message
news:4AD8023E-15B6-40E0...@microsoft.com...
> Who can tell?

Anyone who has loaded Scripting library into an IDE that has an object
browser.

>Maybe the Item is the default property of the Dictionary object

Yes it is.

0 new messages