Dictionary Objects QTP

Dictionary Objects QTP:

The Dictionary object stores name/value pairs (referred to as the key and item respectively) in an array. The key is a unique identifier for the corresponding item and cannot be used for any other item in the same Dictionary object.

The following code creates a Dictionary object called “cars”, adds some key/item pairs, retrieves the item value for the key ‘b’ using the Item property and then outputs the resulting string to the browser.

Code:
<%
Dim cars
Set cars = CreateObject(“Scripting.Dictionary”)
cars.Add “a”, “Alvis”
cars.Add “b”, “Buick”
cars.Add “c”, “Cadillac”
Response.Write “The value corresponding to the key ‘b’ is ” & cars.Item(“b”)
%>

Output:
“The value corresponding to the key ‘b’ is Buick”

PROPERTIES

CompareMode Property
The CompareMode property is used to set and return the key’s string comparison mode which determines how keys are matched while looking up or searching.

Syntax: object.CompareMode[ = comparison_mode]

Count Property
The Count property is used to determine the number of key/item pairs in the Dictionary object.

Syntax: object.Count

Item Property
The Item property allows us to retreive the value of an item in the collection designated by the specified key argument and also to set that value by using itemvalue.

Syntax: object.Item(key) [ = itemvalue]

Key Property
The Key property lets us change the key value of an existing key/item pair.

Syntax: object.Key(keyvalue) = newkeyvalue
 
METHODS

Add Method
The Add method is used to add a new key/item pair to a Dictionary object.

Syntax: object. Addkeyvalue, itemvalue

Exists Method
The Exists method is used to determine whether a key already exists in the specified Dictionary. Returns True if it does and False otherwise.

Syntax: object.Exists(keyvalue)

Items Method
The Items method is used to retreive all of the items in a particular Dictionary object and store them in an array.

Syntax: [arrayname = ]object.Items

Keys Method
The Keys method is used to retreive all of the keys in a particular Dictionary object and store them in an array.

Syntax: [arrayname = ]object.Keys

Remove Method
The Remove method is used to remove a single key/item pair from the specified Dictionary object.

Syntax: object. Remove(keyvalue)

RemoveAll Method
The RemoveAll method is used to remove all the key/item pairs from the specified Dictionary object.

Syntax: object.RemoveAll

 

ERROR OBJECTS

 

Top of Form

The Err object holds information about the last runtime error that occured. It is not necessary to create an instance of this object; it is intrinsic to VBScript. Its default property is Number, which contains an integer representing a VBScript error number or an ActiveX control Status Code (SCODE) number. This value is automatically generated when an error occurs and is reset to zero (no error) after an On Error Resume Next statement or after using the Clear method.

The following code checks the value of the Number property and, if it contains a value other than zero, displays the details in the browser.

Code:
<%
dim numerr, abouterr
On Error Resume Next
Err.Raise 6
numerr = Err.number
abouterr = Err.description
If numerr <> 0 Then
  Response.Write “An Error has occured! Error number ” & numerr & ” of_
                           the type ‘” & abouterr & “‘.”
End If
%>

Output:
“An Error has occured! Error number 6 of the type ‘Overflow’.”

PROPERTIES

Description Property
This property returns or sets a string containing a brief textual description of an error.

Syntax: object.Description [ = string]

HelpContext Property
This property is used to set or return a context ID for a Help topic specified with the HelpFile property.

Syntax: object.HelpContext [ = contextID]

HelpFile Property
This property is used to get or define the path to a Help file.

Syntax: object.HelpFile [ = contextID]

Number Property
This property is used to retrieve or set the value that relates to a specific runtime error.

Syntax: object.Number [ = errnumber]

Source Property
This property lets us determine the object or application that caused an error, and returns a string that contains its Class name or programmatic ID.

Syntax: object.Source [ = string]

METHODS

Clear Method
This method is used to clear the settings of the Error object.

Syntax: object.Clear

Raise Method
This method is used to generate a VBScript runtime error.

Syntax: object. Raise (number[, source, description, helpfile, helpcontext])

Bottom of Form

 

Comments