Author Topic: IDictionary.Exists Method  (Read 3139 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.Exists Method
« on: July 13, 2008, 10:28:27 PM »

The following example illustrates the use of the Exists method.

JScript

Code: [Select]
function keyExists(k)
{
   var fso, s = "";
   d = new ActiveXObject("Scripting.Dictionary");
   d.Add("a", "Athens");
   d.Add("b", "Belgrade");
   d.Add("c", "Cairo");
   if (d.Exists(k))
      s += "Specified key exists.";
   else
      s += "Specified key doesn't exist.";
   return(s);
}

VBScript

Code: [Select]
Function KeyExists
   Dim d, msg   ' 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"
   If d.Exists("c") Then
      msg = "Specified key exists."
   Else
      msg = "Specified key doesn't exist."
   End If
  KeyExists = msg
End Function

PowerBASIC

Code: [Select]
FUNCTION KeyExists () AS STRING

   LOCAL d AS IDictionary
   LOCAL vKey AS VARIANT
   LOCAL vItem AS VARIANT
   LOCAL strMsg AS STRING

   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"
   IF d.Exists(vKey) THEN
      strMesg = "Specified key exists."
   ELSE
      strMsg = "Specified key doesn't exist."
   END OF
   FUNCTION = strMsg

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