Author Topic: IDictionary.Key Property  (Read 2668 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2517
  • User-Rate: +209/-0
  • Gender: Male
IDictionary.Key Property
« on: July 13, 2008, 10:17:36 PM »

The following example illustrates the use of the Key property.

JScript

Code: [Select]
var d;
d = new ActiveXObject("Scripting.Dictionary");
function AddStuff()
{
   var a;
   d.Add("a", "Athens");
   d.Add("b", "Belgrade");
   d.Add("c", "Cairo");
}

function ChangeKey(oldkey, newkey)
{
   var s;
   d.Key("c") = "Ca";
   s = "Key " + oldkey + " changed to " + newkey;
   return(s);
}

VBScript

Code: [Select]
Function ChangeKey
   Dim d   ' Create some variables.
   Set d = CreateObject("Scripting.Dictionary")
   d.Add "a", "Athens"   ' Add some keys and items.
   d.Add "b", "Belgrade"
   d.Add "c", "Cairo"
   d.Key("c") = "d"   ' Set key for "c" to "d".
   DicDemo = d.Item("d")   ' Return associate item.
End Function

PowerBASIC

Code: [Select]
FUNCTION ChangeKey () AS STRING

   LOCAL d AS IDictionary
   LOCAL vKey AS VARIANT
   LOCAL vItem AS VARIANT

   d = NEWCOM "Scripting.Dictionary"
   vKey = "a" : vItem = "Athens"
   d.Add vKey, vItem
   vKey = "b" : vItem = "Belgrade"
   d.Add vKey, vItem
   vKey = "c" : vItem = "Cairo"
   d.Add vKey, vItem
   vKey = "c" ; vItem ="d"
   d.Key(vKey) = vItem
   vItem = d.Item(vKey)
   FUNCTION = VARIANT$(vItem)

END FUNCTION
« Last Edit: July 13, 2008, 10:57:33 PM by José Roca »