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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating an array with request.cookies

Status
Not open for further replies.

mmarkym

Programmer
Mar 23, 2002
54
US
I'm trying to retreive from a cookies collection and pass each value into a variable, an array called strCookie().
I'm get this error....

Error Type:
Sun ONE ASP VBScript runtime (0x800A000D)
Type mismatch

the code is....

<%

dim iCount
dim objRS
dim objConn
dim strConnectionString
dim strCookie()

For iCount = 1 To Request.Form("menu").count
Response.Cookies("menu" & " " & iCount & " ") = Request.Form("menu")(iCount)
Next

'Loop through each Cookie
redim strCookie(0)
For Each x in Request.Cookies(x)
'this is the line the error refers to..
strCookie(x) = Request.cookies(x)

response.write strCookie(x)

Next
 
try taking out the spaces

Response.Cookies("menu_" & iCount) = Request.Form("menu")(iCount)
 
You need to go after your cookie elements a little differently. The snip below should help. From there you should be able to stuff the elements into an array or whatever...

Code:
<%
for each x in request.Cookies("menu")
    response.Write(x & " = " & request.Cookies("menu")(x) & "<br>")
next
%>
 
With this code....

dim iCount
dim strCookie()

For iCount = 1 To Request.Form("menu").count
Response.Cookies("menu")(iCount) = Request.Form("menu")(iCount)
Next

redim strCookie(0)

'Loop through each Cookie
for each x in request.Cookies("menu")
response.Write(x & " = " & request.Cookies("menu")(x) & "<br>")
error refers to this line--- strCookie(x) = request.Cookies("menu")(x)
response.write strCookie(x)
next

I'm getting this error....

Error Type:
Sun ONE ASP VBScript runtime (0x800A0009)
Subscript out of range
 
I guess sometimes an example isn't enough. This will assign the cookie collection for "menu" to strCookie() array.
Code:
i = cint(request.Cookies("menu").count-1)
redim strCookie(i)
n = 0
for each x in request.Cookies("menu")
    	strCookie(n) = request.Cookies("ss")(x)
	n = n+1	  
next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top