Dictionary

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I want to use the dictionary to store unique values but it only works at the
office where they use Excel XP. At home, with Excel 2003, the same code does
not work. I get the error "Incorect use of keyword New". There is a reference
to Microsoft Scripting Runtime at both places. What could be the problem?
Here is the code:
' **********************************************************
Option Explicit
Private mdctDouble As Dictionary
' **********************************************************
Private Sub TestDictionary()
Set mdctDouble = New Dictionary
MsgBox "Jac is already in the dictionary : " & IsDouble("Jac")
MsgBox "Jac is already in the dictionary : " & IsDouble("Jac")
Set mdctDouble = Nothing
End Sub
' ***********************************************************
Private Function IsDouble(ByRef rstrKey As String) As Boolean
If mdctDouble.Exists(rstrKey) Then
IsDouble = True
Else
mdctDouble.Add rstrKey, rstrKey
IsDouble = False
End If
End Function
' ***********************************************************
Thanks in advance.
 
Jac,

In the VBE, go to Tools | References and checkmark "Microsoft Scripting Runtime"

Regards,
Jim Cone
San Francisco, USA
 
Not having two versions of Excel here to play with I can only speculate but
you could try a more explicit declaration

Private mdctDouble As Scripting.Dictionary

HTH
 
Hi Tim,
I do have a reference to Microsoft Scripting Runtime at both places. That
was mentioned in the original post. That is why I suspect some weird
behaviour from Excel and why I need some explanations or ideas.
Thank you for your concern.
 
Hi Jim,
You are quite right. I have to be more explicit in the declaration. I have
to change this line as well:
Set mdctDouble = New Scripting.Dictionary
Thank you for your comment. It has been helpful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top