0% found this document useful (0 votes)
61 views15 pages

A VBScript14

This document provides an overview of the Dictionary object in VBScript, including its properties, methods, and usage. The Dictionary object allows storing items associated with unique keys, similar to a Perl associative array. Properties like Count and methods like Add, Exist, Items, Keys, Remove, and RemoveAll are described. An example function is provided to demonstrate retrieving and iterating over the keys of a Dictionary object.

Uploaded by

johnson manesh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views15 pages

A VBScript14

This document provides an overview of the Dictionary object in VBScript, including its properties, methods, and usage. The Dictionary object allows storing items associated with unique keys, similar to a Perl associative array. Properties like Count and methods like Add, Exist, Items, Keys, Remove, and RemoveAll are described. An example function is provided to demonstrate retrieving and iterating over the keys of a Dictionary object.

Uploaded by

johnson manesh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 15

VBScript

Session 14

1
?What we learn last session
 Regulars Expressions.
 Methods and properties.
 How to use the object and his
collections.
 How to create complex patterns.

2
Subjects for session 14
 Dictionary Object.
 Properties.

 Methods.

3
Dictionary Object
Denotations
 A Dictionary object is the equivalent of a
PERL associative array.
 Items can be any form of data, and are
stored in the array.
 Each item is associated with a unique key.
 The key is used to retrieve an individual
item and is usually a integer or a string,
but can be anything except an array.

4
Dictionary Object
Count Property

 Returns the number of items in a


collection or Dictionary object.
 Read only.
 Syntax
 objDictionary.Count
 The object is always the name of one
of the items in the Applies To list.

5
Dictionary Object
Item Property
 Sets or returns an item for a specified key in a
Dictionary object.
 For collections, returns an item based on the
specified key.
 Syntax
 object.Item(key)[ = newitem]
 If key is not found when changing an item, a new
key is created with the specified newitem.
 If key is not found when attempting to return an
existing item, a new key is created and its
corresponding item is left empty.

6
Dictionary Object
Key Property

 Sets a key in a Dictionary object.


 The newkey is a new value that
replaces the specified key.
 Syntax
object.Key(key) = newkey
 If key is not found when changing a
key, a new key is created and its
associated item is left empty.

7
Dictionary Object
Add Method

 Adds a key and item pair to a


Dictionary object.
 Syntax
object.Add (key, item)
 An error occurs if the key already
exists.

8
Dictionary Object
Exist Method

 Returns true if a specified key


exists in the Dictionary object,
false if it does not.
 Syntax
object.Exists(key)
 The key parameter, is the key value
being searched for in the
Dictionary object.

9
Dictionary Object
Items Method

 Returns an array containing all the


items in a Dictionary object.
 Syntax
object.Items( )

10
Dictionary Object
Keys Method

 Returns an array containing all


existing keys in a Dictionary
object.
 Syntax
object.Keys( )

11
Dictionary Object
Remove Method

 Removes a key, item pair from a


Dictionary object.
 Syntax
object.Keys( )
 An error occurs if the specified key,
item pair does not exist.

12
Dictionary Object
RemoveAll Method

 The RemoveAll method removes


all key, item pairs from a
Dictionary object.
 Syntax
object.RemoveAll( )

13
Function ShowKeys ()
Dim a, d, i, s ' Create some variables.
Set d = CreateObject("Scripting.Dictionary")
' Add some keys and items.
d.Add "a", "Athens" ' : d.Add "b", "Belgrade" : d.Add "c", "Cairo"
a = d.Keys ' Get the keys.
For i = 0 To d.Count -1 ' Iterate the array.
s = s & a(i) & vbNewLine ' Create return string.
Next
ShowKeys = s
End Function

14
Make sure to visit us
 Tutorials
 Articles
 Proikects
 And much more

www.AdvancedQTP.com

15

You might also like