Dictionary object setup problem

pb1
01-18-2008, 01:33 AM
I'm new to the use of Dictionary object.
To begin, I initiated the Visual Basic 6.0(SP6) as follows:
Project -> Reference -> Microsoft Script Control 1.0
Project -> Components -> Microsoft Script Control 1.0

In my Sub I have this coding

Dim Dict As New Dictionary

In the run time I got the following compiler error message:
[Invalid use of New keyword] - highlighting "Dict As New Dictionary"


then I changed to this coding

Set Dict = CreateObject(Scripting.Dictionary)

Again another compiler error message came up:
[variable not defined] - highlighting "Scripting"

I believe there is some fundamental setup missing. Please help!

tHuNd3r
01-18-2008, 08:49 AM
try:

Set Dict = CreateObject("Scripting.Dictionary")

the master
01-18-2008, 09:12 AM
There are 2 ways of doing this. You can use late binding as tHuNd3r has shown but you must declare your variable as an object first


dim Dict as object
Set Dict = CreateObject("Scripting.Dictionary")


You can also use early binding like you were origionally. There are 2 ways to do this.


Dim Dict As New scripting.Dictionary

That is practically the same as you had it in the first place although i always include "scripting" so you know where the dictionary has come from


dim Dict as scripting.dictionary
set dict = new scripting.dictionary

That is the prefered method but you must remember to set dict=nothing before closing your app or leaving the sub if you are defining it in a sub.

Whichever way you try it, it should work though. I cant get it to throw an error. The reason i think you have an error is because you should be referencing "Microsoft scripting runtime" instead of "Microsoft script control"

dilettante
01-18-2008, 11:22 AM
:D Yes, the IDE can get a little picky about specifying the correct library. "Sounding similar" just doesn't cut it somehow.

pb1
01-18-2008, 10:55 PM
Thank you all, in particular to "the master" for your expertise advice.:D

I got through both ways by changing referencing "Microsoft scripting runtime" instead of "Microsoft script control".
However, when Dict = Nothing is executed, it is weird to have this runtime error 450 quoting "wrong number of arguments or invalid property assignement". At present I commented it out and so far running OK.
Any thoughts!:confused:

dilettante
01-18-2008, 11:06 PM
Try:

Set Dict = Nothing

Rockoon
01-18-2008, 11:06 PM
Set Dict = Nothing

(edited to add: is there an echo in here?)

pb1
01-18-2008, 11:52 PM
OK now. I'm so stupid. Thanks a lot!:D

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum