Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy question: Error with Dictionary Obj

Status
Not open for further replies.

TZRick

Programmer
Nov 10, 2002
11
US
Hello experts!

I am getting an "Object Required" error when trying to access an element of a dictionary.

I have a database connection which performs two queries. The first query is saved in a dictionary object as follows:

dim arrOnCall ()
count = 0

while not oRs.EOF

count = count + 1
redim preserve arrOnCall (count)
Set arrOnCall(count) = server.CreateObject("Scripting.Dictionary")
arrOnCall(count).Add "fname", oRs("first_name")
arrOnCall(count).Add "lname", oRs("last_name")
arrOnCall(count).Add "beeper", oRs("fax")
arrOnCall(count).Add "home", oRs("phone")

next
Response.Write arrOnCall (0).item("fname")

...where oRs is the result from the query. The error occurs at the Response.Write line at the bottom and gives the "Object Required" error.

I look forward to your timely responses, as this is time-sensitive.

Thank you in advance!

Taarik.
 
You put the dictionary object into array element #1 but then try to use it out of array element #0

 
Lets just replace the variable "count" with its value and see what we have:

Oh, and we'll start out assuing it is equal to zero.
Code:
1 = 0 + 1
redim preserve arrOnCall (1)
Set arrOnCall(1) = server.CreateObject("Scripting.Dictionary")
arrOnCall(1).Add "fname", oRs("first_name")
arrOnCall(1).Add "lname", oRs("last_name")
arrOnCall(1).Add "beeper", oRs("fax")
arrOnCall(1).Add "home", oRs("phone")

next
Response.Write arrOnCall(0).item("fname")

see?
 
True. I caught that just now. My current code is:

dim arrOnCall ()
dim fname, lname, beeper, home
count = 0

while not oRs.EOF

redim arrOnCall (count + 1)
Set arrOnCall(count) = server.CreateObject("Scripting.Dictionary")
fname = oRs("first_name")
lname = oRs("last_name")
beeper = oRs("fax")
home = oRs("phone")
arrOnCall(count).Add "fname", fname
arrOnCall(count).Add "lname", lname
arrOnCall(count).Add "beeper", beeper
arrOnCall(count).Add "home", home
count = count + 1

'display contents of dictionary. Now I am getting an "Object required" error here.

oRs.movenext
wend
 
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''
C:\INETPUB\ line 60

Code for line 60:
Code:
<font size=5 color=yellow>TELERAD & FLUORO: Dr.&nbsp;<%=arrOnCall(count).item ("fname")%>&nbsp;<%=arrOnCall(count).item ("lname")%>
 
Thank you for your help. I improvised and ran the query twice to get the correct output.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top