Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dictionary to Array

Status
Not open for further replies.

Skie

Programmer
Jun 21, 2004
475
US
I could've swore I've seen this posted before, but I can't find it. I know I can enumerate a dictionary to pull it into an array, but I was pretty sure you could also use the Array function to pull it into an array.

Code:
Dim aArray()
oDictionary = CreateObject("Scripting.Dictionary")
oDictionary.Add 1,"A"
oDictionary.Add 2,"B"
oDictionary.Add 3,"C"
aArray = Array(oDictionary.Items)

I can get it to work with a join on the dictionary then a split on the join, but only if the array isn't already defined.
 
Why not just assign it like this...

Set oDictionary = CreateObject("Scripting.Dictionary")
oDictionary.Add 1,"A"
oDictionary.Add 2,"B"
oDictionary.Add 3,"C"

aArray = oDictionary.Items
Dim i
For i = 0 To UBound(aArray)
WScript.Echo aArray(i)
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I think I may have misunderstood your question...if so, sorry!

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
If you already have a dictionary (something like an associative array), why do you want to convert it to a scalar array ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top