• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Nested Variables

Guest
Jan 24, 2007 Jan 24, 2007

Copy link to clipboard

Copied

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...



TOPICS
Advanced techniques

Views

259

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 24, 2007 Jan 24, 2007
Use evaluate() function. Check the ColdFusion documentation on the function as well, to get familiar with it.

...
if (isdefined(theVar) and evaluate(theVar)eq '') {
...

Votes

Translate

Translate
Enthusiast ,
Jan 24, 2007 Jan 24, 2007

Copy link to clipboard

Copied

Use evaluate() function. Check the ColdFusion documentation on the function as well, to get familiar with it.

...
if (isdefined(theVar) and evaluate(theVar)eq '') {
...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 24, 2007 Jan 24, 2007

Copy link to clipboard

Copied

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, ... ");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 25, 2007 Jan 25, 2007

Copy link to clipboard

Copied

LATEST
> 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation