4 Replies Latest reply on Jun 29, 2006 3:18 PM by Newsgroup_User

    is defined

    JohnGree Level 1
      Hi i need to do something like this but dont think its the right code, as i dont get the right result

      do i have the or in the right place?

      <CFIF NOT IsDefined("session.Username") or ("session.AdminUsername")>
      <CFLOCATION URL="Login.cfm">
      </CFIF>
        • 1. is defined
          BKBK Adobe Community Professional & MVP
          <CFIF NOT IsDefined("session.Username") or NOT IsDefined("session.AdminUsername")>
          <CFLOCATION URL="Login.cfm">
          </CFIF>

          or

          <CFIF NOT (IsDefined("session.Username") or IsDefined("session.AdminUsername"))>
          <CFLOCATION URL="Login.cfm">
          </CFIF>

          depending on what you want.





          • 2. Re: is defined
            Level 7
            Actually shouldn't that be
            NOT IsDefined("...") AND NOT IsDefined("...")

            With an OR operand one of those two options will always be true and the
            cflocation will alway be run. That isn't the desired effect is it?

            BKBK wrote:
            > <CFIF NOT IsDefined("session.Username") or NOT IsDefined("session.AdminUsername")>
            > <CFLOCATION URL="Login.cfm">
            > </CFIF>
            • 3. Re: is defined
              BKBK Adobe Community Professional & MVP
              Actually shouldn't that be NOT IsDefined("...") AND NOT IsDefined("...")
              Perhaps. I did add "depending on what you want", which leaves some leeway. The key suggestion to JohnGree was that the isDefined() function has to be repeated for every variable. Hence, isDefined("var_A") and/or isDefined("var_B"), rather than isDefined("var_A") and/or ("var_B").

              • 4. Re: is defined
                Level 7
                On Thu, 29 Jun 2006 08:48:52 -0700, Ian Skinner wrote:

                > Actually shouldn't that be
                > NOT IsDefined("...") AND NOT IsDefined("...")
                >
                > With an OR operand one of those two options will always be true and the
                > cflocation will alway be run.

                How do you figure that?

                <cfset a = 1>
                <cfset b = 2>
                <cfif not isDefined("a") or not isDefined("b")>
                Either expression was true
                <cfelse>
                Neither expression was true
                </cfif>


                I think you are getting confused with this sort of nonsense:
                <cfif a is not 1 or a is not 2>
                Will always be true: if it's 1, then it's not 2. If it's 2 then it's not
                1.
                </cfif>

                --
                Adam