Discussion Locked

ASP/VBScript Question

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am using the Dictionary object to print out the contents of the Dictionary. However, I am not clear on what the difference is between Key and objDictionary.Item(Key) in the Response.Write line of the sample code below. I originally thought thatobjDictionary.Item(Key) and Key are the same thing, but they print different things, (objDictionary.Item(Key) prints the Dictionary item value, and Key prints the Dictionary item key. For example, Key prints out "Apple" whereas objDictionary.Item(Key) prints out "Red".)

For Each Key In objDictionary

Response.Write "

Key = " & Key & " -- Value = " & objDictionary.Item(Key)

Next

5 replies

by webmaster

I'm not sure what your question is? What you say is true. A dictionary object has 2 parts, a key and a value. It is what is known in computer science school as a "name-value pair" With the key you can access the value.

This is how the dictionaryis designed to work.

likewise, a form field and its value are also name-value pairs, right?

So what is your question?

by bokeefe1

That code will display every entry in the dictionary by displaying the name it was stored under (ie Apple) and the value that was stored for the key (ie Red). Think of the dictionary as a dictionary of fruit colors. Apples are red, Bananas are yellow, etc.

To code this dictionary, you'd have something like (not sure of the syntax):

objDictionary.Item("Apple") = "Red"
objDictionary.Item("Banana") = "Yellow"

Then think of your code as "For each fruit in my fruit color dictionary, tellme the fruit (the key), and it's color (the value)."

This discussion is closed to new replies.