tags:

views:

78

answers:

1

Hi I have a dictionary object in vbscript how can i copy (duplicate) the object in to new dictionary......some thing like i want to clone an existing dictionary object.....

thanks in advance

+1  A: 

Create a new Dictionary object, iterate through the keys in the original dictionary and adds these keys and the corresponding values to the new dictionary, like this:

Function CloneDictionary(Dict)
  Dim newDict
  Set newDict = CreateObject("Scripting.Dictionary")

  For Each key in Dict.Keys
    newDict.Add key, Dict(key)
  Next
  newDict.CompareMode = Dict.CompareMode

  Set CloneDictionary = newDict
End Function

This should be enough in most cases. However, if your original dictionary holds objects, you'll have to implement deep cloning, that is, clone these objects as well.

Helen
Yes thats true..but is there any built in functionality to perform deep cloning
Vineel Kumar Reddy