+ Reply to Thread
Results 1 to 5 of 5

Dictionary

  1. #1
    Jac Tremblay
    Guest

    Dictionary

    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 Tremblay

  2. #2
    Jim Cone
    Guest

    Re: Dictionary

    Jac,

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

    Regards,
    Jim Cone
    San Francisco, USA


    "Jac Tremblay" <[email protected]> wrote in message
    news:[email protected]...
    > 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 Tremblay


  3. #3
    Jim Thomlinson
    Guest

    RE: Dictionary

    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

    "Jac Tremblay" wrote:

    > 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 Tremblay


  4. #4
    Jac Tremblay
    Guest

    Re: Dictionary

    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.


    "Jim Cone" wrote:

    > Jac,
    >
    > In the VBE, go to Tools | References and checkmark "Microsoft Scripting Runtime"
    >
    > Regards,
    > Jim Cone
    > San Francisco, USA
    >
    >
    > "Jac Tremblay" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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 Tremblay

    >


  5. #5
    Jac Tremblay
    Guest

    RE: Dictionary

    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.

    "Jim Thomlinson" wrote:

    > 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
    >
    > "Jac Tremblay" wrote:
    >
    > > 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 Tremblay


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1