Forum Discussion

alarm's avatar
alarm
New Contributor
14 years ago

JavaScript Scripting.Dictionary Keys() and Items() not work...


HI all:



    The document says the dictionary Keys() and Items() return a array that hold the values for keys/values

    but I cannot retrieve values from return array, fallow is my code




function alarmgo2()

{

    dicTmp = new ActiveXObject("Scripting.Dictionary");

    dicTmp.add("Abc", "abc");

    dicTmp.add("Abd", "abc");

    dicTmp.add("Abe", "abc");

    dicTmp.add("Abf", "abc");



    keys_d = dicCooling.Keys();

    

    for (var index=0; index< dicTmp.Count; index++)



    {

        Log.Message(keys_d[index]);//it log none in the log



    }

}




Please help me!! did I do some thing wrong? or It is TC's BUG?





Have a good day.

AlarmChang






2 Replies

  • Hi,



    TC has nothing to do with this at all - this is the way Dictionary and JScript work.

    You should convert safe arrays returned from Keys and Items to JScript-compatible ones by using the toArray method.
  • alarm's avatar
    alarm
    New Contributor
    Hi Jared,



    thank your help!!, it's work.

    fallow is my code.




    function alarmgo3() 



        dicTmp = new ActiveXObject("Scripting.Dictionary"); 

        dicTmp.add("Abc", "abc"); 

        dicTmp.add("Abd", "abc"); 

        dicTmp.add("Abe", "abc"); 

        dicTmp.add("Abf", "abc"); 





        keys_d     = dicTmp.Keys();

        useVBArray = new VBArray(keys_d)

        resArray   = useVBArray.toArray(); 

         

        for (var index=0; index< dicTmp.Count; index++)

        { 



            Log.Message(resArray[index]);//it is work !!

        } 

    }