Written by James McDonald

June 5, 2013

After spending a lot of time coding in jQuery and CakePHP. Which rely heavily on JSON and PHP Arrays respectively I have come to appreciate storing stuff in objects.

Most of my at work Windows scripting stuff is done using VBS so I was searching for a way to store information in the more comfortable to me these days associative array.

I have found the poor mans version in the VBS Scripting.Dictionary object.

Here is a sample:

 

set d = createObject("Scripting.Dictionary")

d.add "source", "c:\admin\bin"
d.add "target", "c:\Program Files\PuTTY"
d.add "a", array("Kim", "Alexander")

if d.exists("source") then
	wscript.echo "Exists"
end if

for each x in d.items

	if isarray(x) then
		for each i in x
			wscript.echo i
		next
	else
		wscript.echo x
	end if
next

if d.exists("2") then
	d.remove ("2")
end if

for each x in d.keys

	wscript.echo x

next

wscript.echo d.item("source")

wscript.echo "Count " & d.Count

d.removeAll() ' clear the dictionary

wscript.echo "Count after clear " & d.Count

wscript.echo "eos"

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…