Forum Discussion

JMassa1976's avatar
JMassa1976
New Contributor
7 years ago

TestComplete javascript implementation of an Dictionary object bugged.

The code example they give for the new "getActiveXObject("Scripting.Dictionary")" implementation of a dictionary is as follows: function DictionaryDemo() { let d = getActiveXObject("Scripting.Dict...
  • tristaanogre's avatar
    7 years ago

    That's because that's the JScript version of the code.   If you go to https://support.smartbear.com/testcomplete/docs/scripting/dictionary-object.html?q=SCripting%20Dictionary and look at the code examples, there are JavaScript, JScript, Python, etc... if you go to the actual JavaScript tab, this is the code that they give.  Notice the bolded lines that are different.

    function DictionaryDemo()
    {
      let d = getActiveXObject("Scripting.Dictionary");
    
      // Add keys and items.
      d.Add("a", "Alphabet");
      d.Add("b", "Book");
      d.Add("c", "Coffee");
    
      // Get the item by key.
      let s = d.Item("c");
      Log.Message(s);
    
      // Assign a new item to the same key.
      d.$set("Item", "c", "Cookie");
      s = d.Item("c"); 
      Log.Message(s);
    
      // Assign a new key to the same item.
      d.$set("Key", "c", "Co");
    
      // Remove second pair.
      d.Remove("b");
      if (d.Exists("b")) 
          Log.Message("The pair exists.") 
        else
          Log.Message("The pair does not exist.")
    }