Exception Error using Dictionary Object
I am receiving an exception error when trying to display the items in a dictionary object.
First, here is my code,
Sub AddItem
'** get list of other items already for this member and place in dictionary **
Dim intMemRefNum
Dim blnNoMemSplItems
blnNoMemSplItems = 0
intMemRefNum = request.Form ("intMemRefNum")
strSQL = "SELECT DetRefNum FROM tblSplPrice WHERE MemRefNum = " & intMemRefNum
Set rst1 = ECommDB.Execute(strSQL)
If rst1.EOF Then
blnNoMemSplItems = 1
Else
Dim dictMemSplItems
Dim intCounter
Dim strItem
Set dictMemSplItems = Server.CreateObject("Scripting.Dictionary")
intCounter = 0
Do While NOT rst1.EOF
'** get ordernum from tblProductdetail based on DetRefNum in tblSplPrice **
strSQL = "SELECT OrderNum FROM tblProductDetail WHERE DetRefNum = " & rst1("DetRefNum")
Set rst2 = ECommDB.Execute(strSQL)
Do While NOT rst2.EOF
strItem = "item" & CStr(intCounter)
response.write "add to dictionary = " & strItem & " ordernum = " & rst2("OrderNum") & "<br>"
dictMemSplItems.Add strItem, rst2("OrderNum")
response.write "dict item = " & dictMemSplItems.item(strItem) & "<br>"
intCounter = intCounter + 1
rst2.MoveNext
Loop
rst1.MoveNext
Loop
End If
rst1.Close
Set rst1 = Nothing
rst2.Close
Set rst2 = Nothing
response.write "item = " & dictMemSplItems.item("item0") & "<br>"
Dim y
for y = 0 to 10
strItem = "item" & CStr(y)
response.write "item = " & dictMemSplItems.item(strItem) & "<br>"
next
set dictMemSplItems = Nothing
End Sub
Second, the error message,
error '80020009'
Exception occurred.
/SiteAdmin/AdmSpecialPricingMulti.asp, line 42
What I am doing is getting some information from one table and then checking it against another table. If there are items in the first table (NOT rst1.EOF) then it pulls up specific information from another table and places it is a dictionary. The dictionary keys are simply based on a counter that is incrimenting on each item added to the dictionary.
The items are being placed in the dictionary fine. You will notice a couple of response.write items. These are simply to verify what is to be written to the dictionary and what is being written. When I run the code, all of the response.write lines work fine. Here is a sample,
add to dictionary = item0 ordernum = SNA433-7
dict item = SNA433-7
add to dictionary = item1 ordernum = KNKT14025BX
dict item = KNKT14025BX
add to dictionary = item2 ordernum = SNA433-8
dict item = SNA433-8
add to dictionary = item3 ordernum = SNA433-9
dict item = SNA433-9
add to dictionary = item4 ordernum = SNA433-10
dict item = SNA433-10
add to dictionary = item5 ordernum = SNA433-10
dict item = SNA433-10
The problem is after the Do...Loops are done and I then try to display item(s) from the dictionary. I can not seem to get it to display one when I ask for it directly as I do in line 42 or looping through items (I receive the same error on line 47 when I remark line 42).
I have worked with dictionaries before and never had this problem. I even tried the following,
for Each Key in dictMemSplItems
response.write dictMemSplItems(key)
next
which has worked for me in other situations but does not now.
Suggestions??
Thanks,
Ian
|