473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to make cookies into an array?

Hi,

I need several cookies depending of an variable (x), so i defined a
HttpCookie() as an array.
My problems:
1)I get the error: Object reference not set to an instance of an object.
2)My second question is: how to request those cookies, because there is no
name?

Thanks
André
I did:
x=5
Dim cok(x) As New HttpCookie 'can't give a name to the cookie
.....

for k=1 to x
cok(k).Value = "cookie" & k
Response.Cookies.Add(cok(k))
next

-----------------------------------
recovering the cookies?
for i=1 to x
cok(i) = Request.Cookies("??")
next

Nov 29 '06 #1
7 2864
If you are using VB2005, you can switch to one of the Generic collections
that includes a key so that you can look up the cookie by name.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)

Add new cookies to the dictionary this way:

allCookies.Add(cookieName, theCookieItself)

Access the cookie this way:

theRetrievedCookie = allCookies(cookieName)

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
Hi,

I need several cookies depending of an variable (x), so i defined a
HttpCookie() as an array.
My problems:
1)I get the error: Object reference not set to an instance of an
object.
2)My second question is: how to request those cookies, because there
is no
name?
Thanks
André
I did:
x=5
Dim cok(x) As New HttpCookie 'can't give a name to the cookie
....
for k=1 to x
cok(k).Value = "cookie" & k
Response.Cookies.Add(cok(k))
next
-----------------------------------
recovering the cookies?
for i=1 to x
cok(i) = Request.Cookies("??")
next

Nov 29 '06 #2
Hi,

thanks for replying ...

I tried this (it must be a loop because i never don't know in advance how
many cookies i need)
But i get the error: "value of type string cannot be converted to
system.web.httpcookie"
How can i give the value of the cookie?
Thanks

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim cc(5) As String
For i = 1 To 5
allCookies.Add(cc(i), "test" & i)
Next


"Tim Patrick" <in*****@invalid.com.invalidschreef in bericht
news:e3*************************@newsgroups.comcas t.net...
If you are using VB2005, you can switch to one of the Generic collections
that includes a key so that you can look up the cookie by name.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)

Add new cookies to the dictionary this way:

allCookies.Add(cookieName, theCookieItself)

Access the cookie this way:

theRetrievedCookie = allCookies(cookieName)

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
>Hi,

I need several cookies depending of an variable (x), so i defined a
HttpCookie() as an array.
My problems:
1)I get the error: Object reference not set to an instance of an
object.
2)My second question is: how to request those cookies, because there
is no
name?
Thanks
André
I did:
x=5
Dim cok(x) As New HttpCookie 'can't give a name to the cookie
....
for k=1 to x
cok(k).Value = "cookie" & k
Response.Cookies.Add(cok(k))
next
-----------------------------------
recovering the cookies?
for i=1 to x
cok(i) = Request.Cookies("??")
next


Nov 29 '06 #3
But you are trying to convert "test1" to a cookie. That is a string, not
a cookie. You must specifically create an instance of HttpCookie, fill in
its constructor or fields as needed, and then store it. I haven't used that
object myself, but the code would be something like this.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim oneCookie As HttpCookie
Dim i As Integer

For counter = 1 To 5
oneCookie = New HttpCookie
' !!! Fill in all of oneCookie's fields here, then...
allCookies.Add("test" & counter, oneCookie)
Next counter

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
Hi,

thanks for replying ...

I tried this (it must be a loop because i never don't know in advance
how
many cookies i need)
But i get the error: "value of type string cannot be converted to
system.web.httpcookie"
How can i give the value of the cookie?
Thanks
Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim cc(5) As String
For i = 1 To 5
allCookies.Add(cc(i), "test" & i)
Next
"Tim Patrick" <in*****@invalid.com.invalidschreef in bericht
news:e3*************************@newsgroups.comcas t.net...
>If you are using VB2005, you can switch to one of the Generic
collections that includes a key so that you can look up the cookie by
name.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)

Add new cookies to the dictionary this way:

allCookies.Add(cookieName, theCookieItself)

Access the cookie this way:

theRetrievedCookie = allCookies(cookieName)

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
>>Hi,

I need several cookies depending of an variable (x), so i defined a
HttpCookie() as an array.
My problems:
1)I get the error: Object reference not set to an instance of an
object.
2)My second question is: how to request those cookies, because there
is no
name?
Thanks
André
I did:
x=5
Dim cok(x) As New HttpCookie 'can't give a name to the cookie
....
for k=1 to x
cok(k).Value = "cookie" & k
Response.Cookies.Add(cok(k))
next
-----------------------------------
recovering the cookies?
for i=1 to x
cok(i) = Request.Cookies("??")
next

Nov 29 '06 #4
Ok, thanks

"Tim Patrick" <in*****@invalid.com.invalidschreef in bericht
news:e3*************************@newsgroups.comcas t.net...
But you are trying to convert "test1" to a cookie. That is a string, not a
cookie. You must specifically create an instance of HttpCookie, fill in
its constructor or fields as needed, and then store it. I haven't used
that object myself, but the code would be something like this.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim oneCookie As HttpCookie
Dim i As Integer

For counter = 1 To 5
oneCookie = New HttpCookie
' !!! Fill in all of oneCookie's fields here, then...
allCookies.Add("test" & counter, oneCookie)
Next counter

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
>Hi,

thanks for replying ...

I tried this (it must be a loop because i never don't know in advance
how
many cookies i need)
But i get the error: "value of type string cannot be converted to
system.web.httpcookie"
How can i give the value of the cookie?
Thanks
Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim cc(5) As String
For i = 1 To 5
allCookies.Add(cc(i), "test" & i)
Next
"Tim Patrick" <in*****@invalid.com.invalidschreef in bericht
news:e3*************************@newsgroups.comca st.net...
>>If you are using VB2005, you can switch to one of the Generic
collections that includes a key so that you can look up the cookie by
name.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)

Add new cookies to the dictionary this way:

allCookies.Add(cookieName, theCookieItself)

Access the cookie this way:

theRetrievedCookie = allCookies(cookieName)

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
Hi,

I need several cookies depending of an variable (x), so i defined a
HttpCookie() as an array.
My problems:
1)I get the error: Object reference not set to an instance of an
object.
2)My second question is: how to request those cookies, because there
is no
name?
Thanks
André
I did:
x=5
Dim cok(x) As New HttpCookie 'can't give a name to the cookie
....
for k=1 to x
cok(k).Value = "cookie" & k
Response.Cookies.Add(cok(k))
next
-----------------------------------
recovering the cookies?
for i=1 to x
cok(i) = Request.Cookies("??")
next


Nov 29 '06 #5
Tim, don't become angry (i'm learning), but it still doesn't work ...

If i do what you wrote here, i get an error with the line:
oneCookie = New HttpCookie

the error is: "overload resolution failed because no accessible 'new'
accepts this number of arguments"

so i tried this (and the error is gone): oneCookie = New HttpCookie("ok")
the whole code is:
Dim allCookies As New Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim oneCookie As HttpCookie
For i = 1 To 5
oneCookie = New HttpCookie("ok")
oneCookie.Value = i
allCookies.Add("test" & i, oneCookie)
Next

But now, how can i retrieve the cookies? I did:

Dim allCookies As New Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim cc(5) As String
Dim retCookie As HttpCookie
For i = 1 To 5
retCookie = allCookies("test" & i)
cc(i) = retCookie.Value
Response.Write(cc(i) & " ")
Next

And the error is now: "The given key was not present in the dictionary"
Can you help me a last time? Thanks


"Tim Patrick" <in*****@invalid.com.invalidschreef in bericht
news:e3*************************@newsgroups.comcas t.net...
But you are trying to convert "test1" to a cookie. That is a string, not a
cookie. You must specifically create an instance of HttpCookie, fill in
its constructor or fields as needed, and then store it. I haven't used
that object myself, but the code would be something like this.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim oneCookie As HttpCookie
Dim i As Integer

For counter = 1 To 5
oneCookie = New HttpCookie
' !!! Fill in all of oneCookie's fields here, then...
allCookies.Add("test" & counter, oneCookie)
Next counter

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
>Hi,

thanks for replying ...

I tried this (it must be a loop because i never don't know in advance
how
many cookies i need)
But i get the error: "value of type string cannot be converted to
system.web.httpcookie"
How can i give the value of the cookie?
Thanks
Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim cc(5) As String
For i = 1 To 5
allCookies.Add(cc(i), "test" & i)
Next
"Tim Patrick" <in*****@invalid.com.invalidschreef in bericht
news:e3*************************@newsgroups.comca st.net...
>>If you are using VB2005, you can switch to one of the Generic
collections that includes a key so that you can look up the cookie by
name.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)

Add new cookies to the dictionary this way:

allCookies.Add(cookieName, theCookieItself)

Access the cookie this way:

theRetrievedCookie = allCookies(cookieName)

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
Hi,

I need several cookies depending of an variable (x), so i defined a
HttpCookie() as an array.
My problems:
1)I get the error: Object reference not set to an instance of an
object.
2)My second question is: how to request those cookies, because there
is no
name?
Thanks
André
I did:
x=5
Dim cok(x) As New HttpCookie 'can't give a name to the cookie
....
for k=1 to x
cok(k).Value = "cookie" & k
Response.Cookies.Add(cok(k))
next
-----------------------------------
recovering the cookies?
for i=1 to x
cok(i) = Request.Cookies("??")
next


Nov 29 '06 #6
Since I'm not sure of what you are doing, I'm not fully sure of the answer
to give you. Cookies are normally only used in the context of a web page,
and ASP.NET exposes two collections of cookies, one through the Request object
and one through the Response object. I'm not sure why you want to create
your own disconnected set of cookies.

I would confirm that you have read up on the HttpCookie object and its related
HttpCookieCollection object (instead of Generic.Dictionary). HttpCookie has
its own name, so it seems a collection-specified name isn't really necessary.

Maybe if you could explain your purpose, it would make the problem easier
to diagnose.

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
Tim, don't become angry (i'm learning), but it still doesn't work ...

If i do what you wrote here, i get an error with the line: oneCookie =
New HttpCookie

the error is: "overload resolution failed because no accessible 'new'
accepts this number of arguments"

so i tried this (and the error is gone): oneCookie = New
HttpCookie("ok")
the whole code is:
Dim allCookies As New Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim oneCookie As HttpCookie
For i = 1 To 5
oneCookie = New HttpCookie("ok")
oneCookie.Value = i
allCookies.Add("test" & i, oneCookie)
Next
But now, how can i retrieve the cookies? I did:

Dim allCookies As New Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim cc(5) As String
Dim retCookie As HttpCookie
For i = 1 To 5
retCookie = allCookies("test" & i)
cc(i) = retCookie.Value
Response.Write(cc(i) & " ")
Next
And the error is now: "The given key was not present in the
dictionary" Can you help me a last time? Thanks

"Tim Patrick" <in*****@invalid.com.invalidschreef in bericht
news:e3*************************@newsgroups.comcas t.net...
>But you are trying to convert "test1" to a cookie. That is a string,
not a cookie. You must specifically create an instance of HttpCookie,
fill in its constructor or fields as needed, and then store it. I
haven't used that object myself, but the code would be something like
this.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim oneCookie As HttpCookie
Dim i As Integer
For counter = 1 To 5
oneCookie = New HttpCookie
' !!! Fill in all of oneCookie's fields here, then...
allCookies.Add("test" & counter, oneCookie)
Next counter
-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
>>Hi,

thanks for replying ...

I tried this (it must be a loop because i never don't know in
advance
how
many cookies i need)
But i get the error: "value of type string cannot be converted to
system.web.httpcookie"
How can i give the value of the cookie?
Thanks
Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim cc(5) As String
For i = 1 To 5
allCookies.Add(cc(i), "test" & i)
Next
"Tim Patrick" <in*****@invalid.com.invalidschreef in bericht
news:e3*************************@newsgroups.comc ast.net...
If you are using VB2005, you can switch to one of the Generic
collections that includes a key so that you can look up the cookie
by name.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)

Add new cookies to the dictionary this way:

allCookies.Add(cookieName, theCookieItself)

Access the cookie this way:

theRetrievedCookie = allCookies(cookieName)

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
Hi,
>
I need several cookies depending of an variable (x), so i defined
a
HttpCookie() as an array.
My problems:
1)I get the error: Object reference not set to an instance of an
object.
2)My second question is: how to request those cookies, because
there
is no
name?
Thanks
André
I did:
x=5
Dim cok(x) As New HttpCookie 'can't give a name to the
cookie
....
for k=1 to x
cok(k).Value = "cookie" & k
Response.Cookies.Add(cok(k))
next
-----------------------------------
recovering the cookies?
for i=1 to x
cok(i) = Request.Cookies("??")
next

Nov 30 '06 #7
Tim, it's ok, i think i understand it now ...
"Tim Patrick" <in*****@invalid.com.invalidschreef in bericht
news:e3*************************@newsgroups.comcas t.net...
Since I'm not sure of what you are doing, I'm not fully sure of the answer
to give you. Cookies are normally only used in the context of a web page,
and ASP.NET exposes two collections of cookies, one through the Request
object and one through the Response object. I'm not sure why you want to
create your own disconnected set of cookies.

I would confirm that you have read up on the HttpCookie object and its
related HttpCookieCollection object (instead of Generic.Dictionary).
HttpCookie has its own name, so it seems a collection-specified name isn't
really necessary.

Maybe if you could explain your purpose, it would make the problem easier
to diagnose.

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
>Tim, don't become angry (i'm learning), but it still doesn't work ...

If i do what you wrote here, i get an error with the line: oneCookie =
New HttpCookie

the error is: "overload resolution failed because no accessible 'new'
accepts this number of arguments"

so i tried this (and the error is gone): oneCookie = New
HttpCookie("ok")
the whole code is:
Dim allCookies As New Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim oneCookie As HttpCookie
For i = 1 To 5
oneCookie = New HttpCookie("ok")
oneCookie.Value = i
allCookies.Add("test" & i, oneCookie)
Next
But now, how can i retrieve the cookies? I did:

Dim allCookies As New Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim cc(5) As String
Dim retCookie As HttpCookie
For i = 1 To 5
retCookie = allCookies("test" & i)
cc(i) = retCookie.Value
Response.Write(cc(i) & " ")
Next
And the error is now: "The given key was not present in the
dictionary" Can you help me a last time? Thanks

"Tim Patrick" <in*****@invalid.com.invalidschreef in bericht
news:e3*************************@newsgroups.comca st.net...
>>But you are trying to convert "test1" to a cookie. That is a string,
not a cookie. You must specifically create an instance of HttpCookie,
fill in its constructor or fields as needed, and then store it. I
haven't used that object myself, but the code would be something like
this.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim oneCookie As HttpCookie
Dim i As Integer
For counter = 1 To 5
oneCookie = New HttpCookie
' !!! Fill in all of oneCookie's fields here, then...
allCookies.Add("test" & counter, oneCookie)
Next counter
-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
Hi,

thanks for replying ...

I tried this (it must be a loop because i never don't know in
advance
how
many cookies i need)
But i get the error: "value of type string cannot be converted to
system.web.httpcookie"
How can i give the value of the cookie?
Thanks
Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim cc(5) As String
For i = 1 To 5
allCookies.Add(cc(i), "test" & i)
Next
"Tim Patrick" <in*****@invalid.com.invalidschreef in bericht
news:e3*************************@newsgroups.com cast.net...
If you are using VB2005, you can switch to one of the Generic
collections that includes a key so that you can look up the cookie
by name.
>
Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
>
Add new cookies to the dictionary this way:
>
allCookies.Add(cookieName, theCookieItself)
>
Access the cookie this way:
>
theRetrievedCookie = allCookies(cookieName)
>
-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
>Hi,
>>
>I need several cookies depending of an variable (x), so i defined
>a
>HttpCookie() as an array.
>My problems:
>1)I get the error: Object reference not set to an instance of an
>object.
>2)My second question is: how to request those cookies, because
>there
>is no
>name?
>Thanks
>André
>I did:
>x=5
>Dim cok(x) As New HttpCookie 'can't give a name to the
>cookie
>....
>for k=1 to x
>cok(k).Value = "cookie" & k
>Response.Cookies.Add(cok(k))
>next
>-----------------------------------
>recovering the cookies?
>for i=1 to x
>cok(i) = Request.Cookies("??")
>next


Nov 30 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: StinkFinger | last post by:
Hello all, I am using two separate setcookies to create and maintain cookies for every day users and one for admins. When a casual user hits a page I use this:...
2
by: Citoyen du Monde | last post by:
Trying to get some ideas on a simple javascript project (to teach myself the language). I want to develop a client-side vocabulary practice application that would allow users to enter their own...
2
by: Chris... | last post by:
I have an application that works just fine under normal conditions. But... When I run it through a "SSL Consentrator" (From Array Network), it starts to send me several (Request) cookies with the...
6
by: Wanda | last post by:
I want to store related data in an array of cookies, is there a way to do it in aspnet? I would like to see something like Response.Cookies(key)(1).Value = "aaa" Response.Cookies(key)(2).Value...
4
by: brett | last post by:
I'm doing this to get a listing of cookies: HttpContext.Current.Request.Cookies.AllKeys and HttpContext.Current.Request.Cookies.AllKeys.ToString() However, that only gives: System.String
4
by: surf_doggie | last post by:
I found that a number of my sites that send email using CDO failed withing the past 30 days. Consider the following. I know its not the best coding practice to open and close the connection so many...
2
by: MartyN | last post by:
When using cookies in classic asp, is it safe to assume that using a comma delimited list of values in one cookie is much more efficient than using multiple cookies? (example below) ...
3
by: Simon Dean | last post by:
Hi, I believe I have a website (I didn't do the original coding) which uses JavaScript/ASP to generate cookies. It's a shopping cart application called UCart I believe. The technologies...
1
by: pedalpete | last post by:
I'm building a facebook app, and have been following the guidelines and posting on the facebook message board, but can't seem to get anywhere. Facebook creates a session and cookie on the users...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.