Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a dictionary of dictionaries in QTP version of VBS?

Something similar to Set<String, Set<String>> in Java?

like image 258
akapulko2020 Avatar asked Jan 26 '12 10:01

akapulko2020


People also ask

What is Dictionary in VBScript?

The VBScript Dictionary object provides an item indexing facility. Dictionaries are part of Microsoft's Script Runtime Library. The Dictionary object is used to hold a set of data values in the form of (key, item) pairs. A dictionary is sometimes called an associative array because it associates a key with an item.

What is Dictionary in uft?

A dictionary object in UFT is very much similar to an array. Unlike an array index, there is a unique key associated with every item of a dictionary object. Using the Key name, the associated value can be called anywhere in the script.

Which method of the data Dictionary object in VBScript will check whether or not the key value pair exists or not?

Exists Method Exist Method helps the user to check whether or not the Key Value pair exists.


1 Answers

A Set is an unordered collection of unique elements. Many Set implementations are based on hash tables (possibly of key-value pairs). VBScript has a Dictionary class -

Dim dicParent : Set dicParent = CreateObject("Scripting.Dictionary")

You can't add the same key twice, so the keys of a VBScript Dictionary represent/model a Set (the Set is ordered (by insertion), however). Nothing keeps you from putting (other) Dictionaries into the values:

>> Dim dicParent : Set dicParent = CreateObject("Scripting.Dictionary")
>> dicParent.Add "Fst", CreateObject("Scripting.Dictionary")
>> dicParent("Fst").Add "Snd", "child of parent"
>> WScript.Echo dicParent("Fst")("Snd")
>>
child of parent

In VBScript (and theory), you can even use objects as keys (not only strings as in other languages):

>> Dim dicParent : Set dicParent = CreateObject("Scripting.Dictionary")
>> Dim dicChild  : Set dicChild  = CreateObject("Scripting.Dictionary")
>> dicParent(dicChild) = "child of parent"
>> WScript.Echo dicParent(dicChild)
>>
child of parent

Your practical mileage may vary.

like image 158
Ekkehard.Horner Avatar answered Nov 15 '22 12:11

Ekkehard.Horner