3 Replies Latest reply on Jan 25, 2007 2:53 AM by Newsgroup_User

    Nested Variables

      Seemingly simple function

      Its usage? <Cfset delStructKey("session.search.this")>

      now, how do i test if the value of session.search.this equal to ''?

      obviously, the code below isn't quite right...



        • 1. Re: Nested Variables
          Fernis Level 3
          Use evaluate() function. Check the ColdFusion documentation on the function as well, to get familiar with it.

          ...
          if (isdefined(theVar) and evaluate(theVar)eq '') {
          ...
          • 2. Re: Nested Variables
            Excellent thanks. For anybody wanting to use the fuction, there was slight changes needed.

            Here is the amended code
            .........
            function delStructKey(structVars) {
            for (i=1;listLen(StructVars);i=i+1) {
            theVar = listGetAt(structVars, i)
            var theKey = listGetAt(theVar, listLen(theVar, "."), ".");
            var theStruct = left(theVar, len(theVar) - len(theKey) - 1);
            if (isdefined('#theVar#') and evaluate(theVar) eq '') {
            structDelete(evaluate(theStruct), '#theKey#');
            }
            }
            }
            .......

            usage:
            delStructKey("session.search.this, structVar2, ... ");
            • 3. Re: Nested Variables
              Level 7
              > Excellent thanks. For anybody wanting to use the fuction, there was slight
              > changes needed.

              Your function will simply error, as you MUST have all your VAR statements
              at the beginning of the function code (they must be the first executable
              statements of the function).

              What exactly is it you're trying to do here, anyhow? It seems to be a
              long-winded way of replicating structDelete()..?

              --
              Adam
              1 person found this helpful