please dont rip this site

Microsoft® Visual Basic® Scripting Edition
Dictionary Object
Language Reference |

See Also                   Properties                    Methods


Description
Object that stores data key, item pairs.

Remarks
A Dictionary object is the equivalent of a PERL associative array. Items, which can be any form of data, are stored in the array using the object.Add key, item method. 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.

The following code illustrates how to create a Dictionary object:

Dim d                   'Create a variable
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens"     'Add some keys and items
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
...

The Item value will be returned if the object is referenced with the key value 'object.[Item](key)[ = newitem]:

Response.Write d("c")	
Response.Write d.Item("c")	

Will display:

CairoCairo

If key is not found when attempting to return an existing item, a new key is created and its corresponding item is left empty. To avoid creating a new key and blank item, use .Exists(key) to check.

if d.Exists("f") then Response.Write d("f")

Keys are, by defaut, case sensitive. To use non-case sensitive keys, set the CompareMode object.CompareMode[ = compare] where  compare is 0 (Binary), 1 (Text), or 2 (Database).

Keys can be replaced using object.Key(key) = newkey or removed using object.Remove(key) which also removes the Item, of course. object.RemoveAll removes all the Keys and Items from the dictionary.

The For each command can be used to enumerate through the dictionary elements.

For each x in d
 Response.Write "<OPTION VALUE=" & x & ">" & d(x)
 Next

will produce a list of the keys:

<OPTION VALUE=a>Athens
<OPTION VALUE=b>Belgrade
<OPTION VALUE=c>Cairo

Note that this code works only because of the "<OPTION>" string being pre-pended to the ilterator. The ilterator is an object and must be converted to a string before use. Null keys and other strange values can cause problems which must me managed via on error or TypeName() checking. Another way to ilterate the dictionary is with object.Keys which returns a zero based Array containing all existing keys and object.Count which returns the number of key/item pairs in the object.

a = d.Keys		'Get the Keys
For i = 0 To d.Count -1 'Iterate the array
 Print a(i) 		'Print Key
 Print d(a(i))		'Print Item for that Key
 Next

It is also possible to ilterate the Items in the dictionary with object.Items which Returns a zero based array containing all existing Items.

a = d.Items		'get the Items
For i = 0 To d.Count -1 'Iterate the array
 Print a(i) 		'Print Item
 Next


© 1996 by Microsoft Corporation.

See also:


file: /Techref/language/asp/vbs/vbscript/277.htm, 5KB, , updated: 2007/8/20 18:20, local time: 2018/5/24 14:53,
TOP NEW HELP FIND: 
54.80.82.9:LOG IN

 ©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE! / 

<A HREF="http://techref.massmind.org/techref/language/asp/vbs/vbscript/277.htm"> Microsoft&reg; Visual Basic&reg; Scripting Edition </A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to techref.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .