Windows Vista Forums

Set and get boolean Session object
  1. #1


    mc. Guest

    Set and get boolean Session object

    Hi all,

    I have an object set in this way

    session("external_user") = RS1.Fields.Item("external_user").Value

    It is a boolean field. I'm trying to get it using this syntax

    <%if (session("external_user") = "1") Then %>

    but I know it's wrong. Do you know the proper one?

    Thank you very much.



      My System SpecsSystem Spec

  2. #2


    Evertjan. Guest

    Re: Set and get boolean Session object

    mc. wrote on 11 feb 2010 in microsoft.public.scripting.vbscript:

    > session("external_user") = RS1.Fields.Item("external_user").Value
    >
    > It is a boolean field. I'm trying to get it using this syntax
    >
    > <%if (session("external_user") = "1") Then %>
    No need for the outermost ().

    You are comparing a bolean to a string, why?

    If it is a bolean:

    <% If session("external_user") Then %>

    or the inverse:

    <% If NOT session("external_user") Then %>

    testing a bolean against true in any form
    is just wasting space and resources.


    > but I know it's wrong. Do you know the proper one?
    >


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

      My System SpecsSystem Spec

  3. #3


    mc. Guest

    Re: Set and get boolean Session object

    Il 11/02/2010 11.18, Evertjan. ha scritto:

    >> session("external_user") = RS1.Fields.Item("external_user").Value

    >> >
    >> > It is a boolean field. I'm trying to get it using this syntax
    >> >
    >> > <%if (session("external_user") = "1") Then %>
    > No need for the outermost ().
    >
    > You are comparing a bolean to a string, why?
    >
    No, sorry, it's an absent-minded mistake =)

    > If it is a bolean:
    >
    > <% If session("external_user") Then %>
    >
    Ok, thank you very much, but after some tests I realize that maybe it is
    notnot so safe.

    If someone sets by mistake session("external_user") = 123

    the previous solution will not raise any error, but this one will do it

    If ( CBool(session("external_user")) )

    do you agree?

      My System SpecsSystem Spec

  4. #4


    Bob Barrows Guest

    Re: Set and get boolean Session object

    mc. wrote:

    > Il 11/02/2010 11.18, Evertjan. ha scritto:
    >

    >>> session("external_user") = RS1.Fields.Item("external_user").Value
    >>>>
    >>>> It is a boolean field. I'm trying to get it using this syntax
    >>>>
    >>>> <%if (session("external_user") = "1") Then %>
    >> No need for the outermost ().
    >>
    >> You are comparing a bolean to a string, why?
    >>
    > No, sorry, it's an absent-minded mistake =)
    >

    >> If it is a bolean:
    >>
    >> <% If session("external_user") Then %>
    >>
    >
    > Ok, thank you very much, but after some tests I realize that maybe it
    > is notnot so safe.
    >
    > If someone sets by mistake session("external_user") = 123
    >
    > the previous solution will not raise any error, but this one will do
    > it
    >
    > If ( CBool(session("external_user")) )
    >
    > do you agree?
    It depends on how you want 123 to be interpreted. CBool(123) will return
    True - is that the intent?
    FYI, in vbscript, a numeric value other than zero will be interpreted as
    True.

    --
    HTH,
    Bob Barrows



      My System SpecsSystem Spec

  5. #5


    Al Dunbar Guest

    Re: Set and get boolean Session object



    "Evertjan." <exjxw.hannivoort@newsgroup> wrote in message
    news:Xns9D1C730DB17DEeejj99@newsgroup

    > mc. wrote on 11 feb 2010 in microsoft.public.scripting.vbscript:
    >

    >> session("external_user") = RS1.Fields.Item("external_user").Value
    >>
    >> It is a boolean field. I'm trying to get it using this syntax
    >>
    >> <%if (session("external_user") = "1") Then %>
    >
    > No need for the outermost ().
    No actual need, but I use them and find that they help separate the boolean
    expression from the "if" and the "then".

    > You are comparing a bolean to a string, why?
    >
    > If it is a bolean:
    >
    > <% If session("external_user") Then %>
    >
    > or the inverse:
    >
    > <% If NOT session("external_user") Then %>
    >
    > testing a bolean against true in any form
    > is just wasting space and resources.
    Agreed! And it can also obfuscate by making things more complicated than
    necessary:

    if a = b then...
    if it is true that a = b then...
    if it is true that it is true that a = b then...


    /Al

    >
    >

    >> but I know it's wrong. Do you know the proper one?
    >>
    >
    >
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)

      My System SpecsSystem Spec

Set and get boolean Session object problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
boolean localization problem Heinz VB Script 21 27 Jun 2009
When and how to set a boolean variable to true? Curious .NET General 1 05 Aug 2008
VPN Session Icon Disappears, so I can't close Session mcambrose Vista file management 0 29 Nov 2007
Boolean searchs in Photo Gallery? Billerr Vista file management 0 12 Oct 2007
Adding canonical aliases for Compare-Object, Measure-Object, New-Object Alex K. Angelopoulos [MVP] PowerShell 2 26 May 2006