option explicit

!INC Local Scripts.EAConstants-VBScript

'
' An example of working with VBScript dictionaries. 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 an integer or a string, 
' but can be anything except an array.
' 
' Related APIs
' ============================================================================= 
' Dictionary Object - http://msdn.microsoft.com/en-us/library/x4k5wbx4.aspx
' 
 
sub DictionaryExample()

	' Show the script output window
	Repository.EnsureOutputVisible "Script"

	dim i
	Session.Output "VBScript DICTIONARY EXAMPLE" 
	Session.Output "======================================="
	
	' Instantiate an object of class Scripting.Dictionary
	dim theDictionary
	set theDictionary = CreateObject( "Scripting.Dictionary" )
	
	' Add items to the Dictionary. Keys are usually strings or integers, but can be any type
	' except for an array.
	theDictionary.Add "a", "Alpha"
	theDictionary.Add "b", "Bravo"
	theDictionary.Add "c", "Charlie"
	theDictionary.Add "d", "Delta"
	theDictionary.Add "e", "Echo"
	
	' The Count property can be used to determine the amount of items in the Dictionary
	dim itemCount 
	itemCount = theDictionary.Count
	Session.Output "The dictionary has " & itemCount & " item(s) in it."
	
	' The Exists method can be used to determine if there is an entry in the Dictionary mapped
	' against the provided key:
	if theDictionary.Exists("a") then
		Session.Output "There is an entry for 'a' in the Dictionary"
	else
		Session.Output "There is no entry for 'a' in the Dictionary"
	end if
	
	if theDictionary.Exists("f") then
		Session.Output "There is an entry for 'f' in the Dictionary"
	else
		Session.Output "There is no entry for 'f' in the Dictionary"
	end if


	' The Item property can be used to retrieve an item mapped against a provided key
	dim theItem 
	theItem = theDictionary.Item( "d" )
	Session.Output "The entry for 'd' is: '" & theItem & "'"

	' The Items method returns all items in the map as an array
	Session.Output "A dump of the entire dictionary:"
	dim allItems
	allItems = theDictionary.Items
	
	dim item
	dim itemCounter
	itemCounter = 0
	
	for each item in allItems
		Session.Output "Item " & itemCounter & ": " & item
		itemCounter = itemCounter + 1
	next
	
		
	' The Remove method removes the item mapped to the provided key
	theDictionary.Remove( "c" )
	Session.Output "The dictionary has " & theDictionary.Count & " item(s) in it."

	' The RemoveAll method removes all items in the dictionary
	theDictionary.RemoveAll()
	Session.Output "The dictionary has " & theDictionary.Count & " item(s) in it."
	
	Session.Output "Done!"
	
end sub

DictionaryExample
