473,385 Members | 1,867 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,385 software developers and data experts.

Variables as cookie keys?

Have a look at the following ASP code;

<%Response.Buffer=true%>
<HTML>
<BODY>

<%
Dim itema
Dim itemqa

itema="121"
itemqa=2

Response.Cookies("List")(itema)=itemqa

%>
I want to create a simple shopping cart.
It seems the computer won't let itema be
anything other than a string. How can I
specify an item number without having
to declare it within the script?
Nov 19 '05 #1
3 996
Well by having itema="121" the quotes make it a string.

itemqa=2 without quotes, makes it an integer by default.

So, with all of this said, you need to pick a datatype and stick with
it. If you're trying to get itema = itemqa you could either change
itemqa into a string, or simply make it a string instead of an
integer...

I hope this helps, also I have trouble understanding your last
question. If it's a variable that you are using, I believe you have to
declare it.

Nov 19 '05 #2
Hi Chad,

Thanks for your intervention. However,
a flash of inspiration gave me the answer.

Cookie keys *have* to be strings - they cannot be integers.
I wanted a way of storing integer values and get them back.

<%
Dim itema
Dim sitema
Dim itemqa

itema=121+4
itemqa=2
sitema=CStr(itema)

Response.Cookies("List")(sitema)=itemqa
Response.Cookies("List")("item2")="2"
Response.Cookies("List")("item3")="3"
%>

The answer is a simple conversion from integer (here itema)
to string (sitema) using the CStr command. This allows anyone
to use an integer as a cookie key value. It can be read back by
using the command CInt (if ever the viewer wanted to save
an integer value to a access database for example).
James

"Chad Devine" <su*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Well by having itema="121" the quotes make it a string.

itemqa=2 without quotes, makes it an integer by default.

So, with all of this said, you need to pick a datatype and stick with
it. If you're trying to get itema = itemqa you could either change
itemqa into a string, or simply make it a string instead of an
integer...

I hope this helps, also I have trouble understanding your last
question. If it's a variable that you are using, I believe you have to
declare it.

Nov 19 '05 #3
Ah you're right, thanks for posting the answer. :D

Nov 19 '05 #4

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

Similar topics

1
by: Mike | last post by:
Hello, I can't find any javascript that reads and writes cookies with keys, so that it is compatible with ASP (I want to read and write cookies from both javascript and ASP) for example in...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
5
by: Jim Heavey | last post by:
How would I iterate over the session varriables listing all the names of the session variables which currently exist? Why would it be that if I set a session variable and then immediately...
4
by: Cowboy \(Gregory A. Beamer\) | last post by:
Background: ------------- The idea started as a single sign on type of application. Having tested it before, I knew we could institute single sign on using the same Authentication Cookie name (in...
1
by: Steve Remer | last post by:
My application (relevant code snippets below) originally used Session variables in order to maintain state from page to page. After being unable to solve the mystery of why those variables were...
6
by: Jason Collins | last post by:
There seems to be an inconsistency (bug?) in the way the Set-Cookie header is handled by the WebHeaderCollection. That is, the values of Set-Cookie, when an Expires is specified, contain the ","...
7
by: Victor | last post by:
I've got two domain names sharing the same IP address that use ASP VBScript If I set a session variable with domain 1, it is only available for domain 1 - this is correct? If I set an...
2
by: Niko | last post by:
Hi I have a big problem with some browser setting wrong ASP.NETSessionid in a cookie, and the result is that asp.net 1.1 always assigns new session to the client. I checked what is going on and...
103
by: chochote | last post by:
Hi, I have a PHP script that does some processing, and stores an error message as a variable. The script then redirects to another script with the error string in the URL, with the second script...
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.