The following sample does not work:

class clsX
public m1
public m2
end class

set objDict = CreateObject("Scripting.Dictionary")
set w = new clsX
w.m1 = "foo"
w.m2 = "bar"
objDict.Add "0", w
w.m1 = "FOO"
w.m2 = "BAR"
objDict.Item("0") = w 'Object doesn't support property or method
objDict.Item("0") = "fubar" 'Works OK

The line "objDict.Item("0") = w" produces the error:
Object doesn't support this property or method.

Remove that line and the subsequent line "objDict.Item("0") = "fubar""
works just fine.

The Item() method/property only permits string variants to be assigned
to it?

Re: Dictionary Item() does not like objects? by Tom

Tom
Fri Apr 07 13:29:13 CDT 2006

Try ...

set objDict.Item("0") = w

Tom Lavedas
============
http://members.cox.net/tglbatch/wshindex.html

Arnie wrote:
> The following sample does not work:
>
> class clsX
> public m1
> public m2
> end class
>
> set objDict = CreateObject("Scripting.Dictionary")
> set w = new clsX
> w.m1 = "foo"
> w.m2 = "bar"
> objDict.Add "0", w
> w.m1 = "FOO"
> w.m2 = "BAR"
> objDict.Item("0") = w 'Object doesn't support property or method
> objDict.Item("0") = "fubar" 'Works OK
>
> The line "objDict.Item("0") = w" produces the error:
> Object doesn't support this property or method.
>
> Remove that line and the subsequent line "objDict.Item("0") = "fubar""
> works just fine.
>
> The Item() method/property only permits string variants to be assigned
> to it?


Re: Dictionary Item() does not like objects? by ekkehard

ekkehard
Fri Apr 07 13:31:54 CDT 2006

Arnie wrote:

> The following sample does not work:
>
> class clsX
> public m1
> public m2
> end class
>
> set objDict = CreateObject("Scripting.Dictionary")
> set w = new clsX
> w.m1 = "foo"
> w.m2 = "bar"
> objDict.Add "0", w
> w.m1 = "FOO"
> w.m2 = "BAR"
> objDict.Item("0") = w 'Object doesn't support property or method
> objDict.Item("0") = "fubar" 'Works OK
>
> The line "objDict.Item("0") = w" produces the error:
> Object doesn't support this property or method.
>
> Remove that line and the subsequent line "objDict.Item("0") = "fubar""
> works just fine.
>
> The Item() method/property only permits string variants to be assigned
> to it?
>
You must use Set, e.g:

Dim dicObjStore : Set dicObjStore = CreateObject( "Scripting.Dictionary" )
Dim oODTest : Set oODTest = New cODTest

oODTest.m_sHelp = "use set to set me"
dicObjStore.Add "0", oODTest
dicObjStore.Add "1", "string"

WScript.Echo "(0) ", dicObjStore( "0" ).m_sHelp

WScript.Echo "(1) ", dicObjStore( "1" )
dicObjStore( "1" ) = "no set for string"
WScript.Echo "(2) ", dicObjStore( "1" )

Set dicObjStore( "1" ) = oODTest
WScript.Echo "(3) ", dicObjStore( "1" ).m_sHelp

dicObjStore( "0" ).m_sHelp = "ok"
WScript.Echo "(4) ", oODTest.m_sHelp
WScript.Echo "(5) ", dicObjStore( "1" ).m_sHelp