PDA

View Full Version : scripting.Dictionary ... confusing myself!


rlaxton
04-22-2004, 10:13 PM
I'm attempting to create a few scripting.dictionary's depending on a value in a field on each record. The error I'm getting is:
Object required: 'd4'
(stopping on line 50 which is the d.add line ...)

So, this is the code I have so far:

rsUnique = "Select DISTINCT ownerID from Sites Where customerID = "
rsUnique = rsUnique & session(ID)
conn.execute(rsUnique)
while not rsUnique.EOF
dim d
d = "d" & rsUnique("OwnerID")
set d = server.createObject ("Scripting.Dictionary")
rsUnique.MoveNext
wEnd
'*** SCRIPTING DICTIONARY ***
rsBlah = "Select * from Sites where customerID = " & session("ID")
rsBlah = rsBlah & " order by ownerID, siteID")
dim rsID,rsName
while not rsBlah.EOF
If rsBlah("ownerID") <> x Then
d = "d" & rsBlah("ownerID")
End If
i = i + 1
rsID = rsBlah("siteID")
rsName = rsBlah("siteName")
rsname2 = rsBlah("OwnerID")
d.Add rsID, rsName&","&rsname2
a = d.Items
b = d.keys
rsBlah.moveNext
wEnd
for i = 0 to d.count -1
s = s & b(i) & a(i) & "<BR>"
next
response.write s
response.write "done<br>"


I'm Perfectly new to scripting.Dictionary, so bare with me or recommend a site to read up on it all!! What I'm hoping to accomplish from the above is to have a d# for each OwnerID that will list all Sites that fall under that ownerID for use in dynamic <select ...>
Thanks for any input / help!!

rlaxton
04-23-2004, 04:36 PM
Above is a bit messy. I went through the code and figured out my loop on the first record set should've been at the end of the whole thing. Works fine now. Still need to figure out how to access the data!!

glenngv
04-26-2004, 06:49 AM
You access the data by:

DictionaryObject.Item("key")

See sample code below:

<%
Dim cars
Set cars = CreateObject("Scripting.Dictionary")
cars.Add "a", "Alvis"
cars.Add "b", "Buick"
cars.Add "c", "Cadillac"
Response.Write "The value corresponding to the key 'b' is " & cars.Item("b")
%>
Output:
The value corresponding to the key 'b' is Buick