Dictionary Object Key Value Pair in QTP/UFT

Spread the love
  • 23
  • 22
  • 12
  • 35

The below things can be done using Item Property:

  1. We can add new item to Dictionary Object(I have shown already)
  2. We can update a item in Dictionary Object(Same technique)
  3. We can read an Item from Dictionary Object


Things Method

The Items strategy is utilized to retrieve the majority of the things in a specific Dictionary article and store them in an exhibit.

a = myVar.Items ' Get the items.
For i = 0 To myVar.Count -1 ' Iterate the array.
s = s & a(i) & "
" ' Create return string.
DicDemo = s

Evacuate/Remove Method

The Remove technique is utilized to evacuate a solitary key/thing pair from the predetermined Dictionary object.It is also important to use an Exist() method before use of remove() method. Otherwise it will throw an error.

RemoveAll Method

The RemoveAll technique is utilized to expel all the key/thing sets from the predefined Dictionary object.

myVar.Remove("b") ' Remove second pair.
a = myVar.RemoveAll ' Clear the dictionary.

Summary of Dictionary Object:

Method or Property Return Description
Add NA Adds a new member to the dictionary
Exists Boolean true false test if a given key is in
the dictionary
Items array Returns all the values in a dictionary in the form of an array
Keys array Returns all the keys in a dictionary in the form of an array
Remove NA Removes the item corresponding to the
given key
RemoveAll NA make the dictionary empty by removing all members
Count int Returns the number of items in a
Item Variant Sets and returns an item for the
specified key
Key NA Changes an item’s key

Difference between Array and Dictionary Object in VBScript or UFT?

Imagine a table like below:

0 1 2
0 Name Roll Phone
1 xyz 1001 89654566
2 abc 1002 78893839

These kind of data structure is tough to read via Array. As we need to loop through the entire data structure using loop variables to get the correct data.One variable will go along with the columns and other one through rows.

Dictionary Objects on the other hand solve these kind of issues by using an Associative Array concept. It means each item in the rows has a unique key associated with it.

Both arrays and dictionaries are holders and can be perused sequentially (for example arrays can be listed by methods for a file and dictionaries by methods for a key). Yet, while arrays keep up the request among objects, dictionaries not.

What’s more, with dictionaries you have the likelihood to get to a particular element with a particular key in a more easy to understand way (a memory aide one).Alternatively we can use comments.

An Array hold an index value as numeric though in dictionary object, record esteem can be string. Thus while alluding any an incentive with key, a key can have any name related with an esteem.

While both can be used in our scripts,Dictionary objects in general are used as global variable and arrays we use as local variable.

  1. An array is a like holder object which holds a fixed number of estimations of a solitary kind.
  2. We can have dynamic array.
  3. Array does not have meany methods like Dictionary.
  4. Arrays can be dynamic in qtp/uft or some other programming ex: Redim to change the array estimate
  5. Before utilizing an array we should announce the extent of an array.
  6. If we need to expand the array measure in content we need to utilize Redim articulation to build the array.
  7. QTP/UFT does not have any technique to discharge the memory on the off chance that any component isn’t required.
  8. We can have multi dimensional array to work with.
  9. Deletion from inside of an Array costs more as other elements need to move up. For this we need to create one more array and transfer the remaining items.This back and forth operation comes with huge cost interms of speed.

Dictionary object has numerous builtin capacities which can include, expel, get to the components utilizing one of a kind key.

  1. QTP/UFT does not have any idea like dynamic Dictionary
  2. setting up size of the dictionary in QTP/UFT is not required.
  3. Not required to utilize any announcement to include additional element,just use include method.
  4. Dictionary supports many methods like add,delete etc.
  5. Can expel components which is never again valuable.
  6. We do not have multi dimensional Dictionary to work with.
  7. The deletion process is super easy. The internal mechanism of Dictionary automatically moves the elements up upon deletion of an item.

What’s the final Call?

Dictionary object was utilized with the record-index(key) being string. On account of array, the list can be ONLY numeric. At that point obviously we have some undeniable favorable circumstances like referencing an incentive with an important keys and so forth. While Array gives us flexibility to use duplicate entry, Dictionary object does not allow duplicate entry.

Dictionary Object is more useful and versatile replacement of an Array.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 23
  • 22
  • 12
  • 35



Please enter your comment!
Please enter your name here