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

Checking for Session cookies

I was looking at different ways of doing the same thing and at the moment
was looking at the use of "is" and "=", as I have at times found that I will
do something like

if something = 0

and will get an error that says I can't use "=" (or <>) in this case case I
must use "is" ( or not something is). I am trying to find out when this is
the case - when I can use the "=" and when I have to use "is.

For example, I have a small piece of code checking for the existance of a
session cookie:

if session("tom") = nothing then
trace.warn("Tom not there")
trace.warn("Len(session('Tom')) = " & Len(session("Tom")))
if len(session("Tom")) = 0 then
trace.warn("also got a hit on <> 0")
end if
end if
This can also be run as:

if session("tom") is nothing then
trace.warn("Tom not there")
trace.warn("Len(session('Tom')) = " & Len(session("Tom")))
if len(session("Tom")) = 0 then
trace.warn("also got a hit on <> 0")
end if
end if

So 'session("Tom") = nothing' and 'session("Tom") is nothing' as well as
'Len(session("Tom"))' are all equivalent.

Not sure if there is a best way or just whatever strikes you fancy.

I do know that in some cases you can't use the "=" and must use "is". I
just don't know why in some cases you can use both (or all 3 ways) and in
some cases you must us "is".

Can someone help me out on the difference?

Thanks,

Tom
Nov 19 '05 #1
2 1150
There are 2 sorts of types if you program in an OO language : reference and
value types

Value types are most built in types like integer, string (I think), money,
etc and you can think of the variable as actualy holding the value.
A reference type is Nothing (null in c#) or contains a reference to the actual
value which is always a class.

If you use a reference type and you want to know whether it contains a value
you do this by asking " is nothing", ie you are asking if it contains a reference.

But VB.NEt isn't so strict and it allows things like

dim i as integer = 5
if i = nothing then ...

This is not stritly right as i is a value type. But VB.NET guessed what you
ment (but guessing is a bad idea for a compiler).

So to be short : if you are dealing with classes you have to use nothing.

To complicate things further structs are value types. I suggest you google
for "difference reference value type" to dig in deeper cause it's quit a
technical topic.

Let me know if you have any more questions..

Cheers,
Tom Pester
I was looking at different ways of doing the same thing and at the
moment was looking at the use of "is" and "=", as I have at times
found that I will do something like

if something = 0

and will get an error that says I can't use "=" (or <>) in this case
case I must use "is" ( or not something is). I am trying to find out
when this is the case - when I can use the "=" and when I have to use
"is.

For example, I have a small piece of code checking for the existance
of a session cookie:

if session("tom") = nothing then
trace.warn("Tom not there")
trace.warn("Len(session('Tom')) = " & Len(session("Tom")))
if len(session("Tom")) = 0 then
trace.warn("also got a hit on <> 0")
end if
end if
This can also be run as:

if session("tom") is nothing then
trace.warn("Tom not there")
trace.warn("Len(session('Tom')) = " & Len(session("Tom")))
if len(session("Tom")) = 0 then
trace.warn("also got a hit on <> 0")
end if
end if
So 'session("Tom") = nothing' and 'session("Tom") is nothing' as well
as 'Len(session("Tom"))' are all equivalent.

Not sure if there is a best way or just whatever strikes you fancy.

I do know that in some cases you can't use the "=" and must use "is".
I just don't know why in some cases you can use both (or all 3 ways)
and in some cases you must us "is".

Can someone help me out on the difference?

Thanks,

Tom

Nov 19 '05 #2
I found a good text about it :

http://www.awprofessional.com/conten...gner_item6.pdf

Cheers,
Tom Pester
Nov 19 '05 #3

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

Similar topics

0
by: Maverick | last post by:
Hello all, I read some good reviews about jakarta HTTPClient about its session and cookies management system and fancied giving it a try as a learning exercise but somehow I don't seem to be able...
3
by: PM | last post by:
I'm trying to make a kind of search history containing the 3 last searched words. So I'm using 3 Session Variables: Word1 / Word2 / Word3. In order to get this history working, I need to put the...
2
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
9
by: RA | last post by:
Hi Please review and let me know if I am correct: 1) My understanding from reading http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/ diforwc-ch05.asp is that...
7
by: Marcus | last post by:
I know that when you start a session in PHP, the "cookie" it creates is not the same as those that are stored in your browser's temp folder, and instead is kept in RAM. I am confused because in...
4
by: Jeff | last post by:
I have a vb.net application (2005) requiring session variables and want to test to make certain that the user's cookies are enabled. I can set a test session variable on one page and attempt to...
4
Bob Ross
by: Bob Ross | last post by:
I'm sure I know the answer to this already but.... Does anyone know a good way of checking if cookies are enabled on a browser? I currently have If Request.QueryString("Trying") =...
2
by: StanB | last post by:
I came across this weird problem: 1. Session state stops working after the app is deployed to another server because IE does not accept cookies. 2. It works if cookieless="true" in the...
3
by: dihola | last post by:
Hi, I have a website running in IIS7 and it seems to be creating a new session for every request I make. The values I store in Session are lost with every request. This is the forms bit in my...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.