PC Review


Reply
Thread Tools Rate Thread

Array within a dictionary

 
 
jrpfinch
Guest
Posts: n/a
 
      20th Nov 2009
Please could somebody help me why this code does not work as expected
in Excel 2003:

Sub Test()
Dim dic As Dictionary
Set dic = New Dictionary

dic("Hello") = Array("Zero", "Item1")
Debug.Print dic("Hello")(0)
Debug.Print dic("Hello")(1)

dic("Hello")(1) = dic("Hello")(1) & ",Item2"
Debug.Print dic("Hello")(1)

End Sub

Output:
Zero
Item1
Item1





Thanks

Jon
 
Reply With Quote
 
 
 
 
Jarek Kujawa
Guest
Posts: n/a
 
      20th Nov 2009
this code:

Sub Test()
Dim hello()


hello = Array("Zero", "Item1")
Debug.Print hello(0)
Debug.Print hello(1)


hello(1) = hello(1) & ",Item2"
Debug.Print hello(1)


End Sub

will bring:
Zero
Item1
Item1,Item2

as the results


On 20 Lis, 13:54, jrpfinch <jrpfi...@gmail.com> wrote:
> Please could somebody help me why this code does not work as expected
> in Excel 2003:
>
> Sub Test()
> Dim dic As Dictionary
> Set dic = New Dictionary
>
> dic("Hello") = Array("Zero", "Item1")
> Debug.Print dic("Hello")(0)
> Debug.Print dic("Hello")(1)
>
> dic("Hello")(1) = dic("Hello")(1) & ",Item2"
> Debug.Print dic("Hello")(1)
>
> End Sub
>
> Output:
> Zero
> Item1
> Item1
>
> Thanks
>
> Jon


 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      20th Nov 2009
I believe that in order to change an item in the array, the entire array
needs to be changed at the same time.
If I understand the question correctly, here is one idea...

Sub Demo()
Dim Dic
Dim M 'Matrix Array

Set Dic = CreateObject("Scripting.Dictionary")

' Add Key, Item (Both Required)
Dic.Add "Hello", Array("Zero", "Item1")

Debug.Print Dic("Hello")(0)
Debug.Print Dic("Hello")(1)

'Get Data to change
M = Dic("Hello")
'New Data
M(1) = M(1) & ", Item2"
'Change it
Dic("Hello") = M

Debug.Print Dic("Hello")(0)
Debug.Print Dic("Hello")(1)
End Sub

= = = = =
HTH
Dana DeLouis


jrpfinch wrote:
> Please could somebody help me why this code does not work as expected
> in Excel 2003:
>
> Sub Test()
> Dim dic As Dictionary
> Set dic = New Dictionary
>
> dic("Hello") = Array("Zero", "Item1")
> Debug.Print dic("Hello")(0)
> Debug.Print dic("Hello")(1)
>
> dic("Hello")(1) = dic("Hello")(1) & ",Item2"
> Debug.Print dic("Hello")(1)
>
> End Sub
>
> Output:
> Zero
> Item1
> Item1
>
>
>
>
>
> Thanks
>
> Jon

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dictionary->(item, item, item); Can dictionary point to an array inVBA? cate Microsoft Excel Programming 1 6th Mar 2010 10:15 PM
Cpying Dictionary to Array Luigi Microsoft C# .NET 2 1st Oct 2008 01:33 PM
Converting a Dictionary to an array? Gustaf Microsoft C# .NET 20 18th Dec 2006 10:26 PM
Please Help: Transferring from Dictionary to Array =?Utf-8?B?TWFnbml2eQ==?= Microsoft Excel Programming 2 2nd Sep 2006 06:13 AM
Dictionary vs. Array =?Utf-8?B?QmVuIEVuZmllbGQ=?= Microsoft Dot NET 2 26th Jul 2005 04:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:40 PM.