Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Array within a dictionary

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 896
Default Array within a dictionary

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 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Array within a dictionary

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Speed up Array Transfer to Dictionary ExcelMonkey Excel Programming 6 May 27th 09 05:00 PM
Please Help: Transferring from Dictionary to Array Magnivy Excel Programming 2 September 2nd 06 06:13 AM
HELP-Dictionary dfisch8 Excel Programming 3 August 22nd 05 08:27 PM
dictionary Libby Excel Programming 0 November 15th 04 12:53 PM


All times are GMT +1. The time now is 12:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"