Saturday, March 24, 2012

Operator And is not defined for types System.Web.HttpCookie?

I have declared 2 variables as HttpCookie objects. Im trying to check if both are non-existent but I get an error when I use the "AND" operator. here is the code in reference:

--
Dim objcookie As HttpCookie
objcookie = Request.Cookies("ckusername")
Dim objckuserid As HttpCookie
objckuserid = Request.Cookies("ckuserid")

If objcookie AND objckuserid Is Nothing Then <------
--

I get this error when I execute the page:

Compiler Error Message: BC30452: Operator 'And' is not defined for types 'System.Web.HttpCookie' and 'Boolean'.What you're doin ghtere is ANDing the cookies together, not the boolean values. You should also use the andalso operator here, as it's relatively faster:

If (objCookie is Nothing) AndAlso (objckUserId is Nothing) Then
...
End If
<oops> that was exactly it! thanks.

0 comments:

Post a Comment