Solved

Custom Tag Question

Posted on 2001-06-20
4
281 Views
Last Modified: 2013-12-24
Here is what I am trying to do:
 
 <cfset myArray = ArrayNew(1)>
 <cfset myArray[1] = StrucNew()>

 <cf_ctReturnSomething
      r_stOutput = "myArray[1]"
 >
 
where ctReturnSomething custom tag is defined as follows:
 
<cfset myStruct = StructNew()>
<cfset myStruct.junk = 2>
<cfset "Caller.#Attributes.r_stOutput#" = myStruct>

The problem:
The return assignment in the custom tag fails when it is desired to stuff the retun value directly into an array slot.

0
Comment
Question by:Scott Bennett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:CF_Spike
ID: 6213604
Why don't you just add an extra line after the custom tag?

cfset myArray = ArrayNew(1)>
<cfset myArray[1] = StrucNew()>

<cf_ctReturnSomething
     r_stOutput = "stReturn"
>

<cfset myArray[1] = StructCopy(stReturn)>

I think that the problem with what you are doing is that the return variable is being seen as a string and not a variable. If you really want to get it to work you could try playing around with Evaluate().

Spike
0
 
LVL 14

Author Comment

by:Scott Bennett
ID: 6215392
In order to get my code to work I actaully thought of and did what you suggested (which is to have the tag return a structure and insert the stucture into the array in a seperate line of code) before I ever posted this question.
   However, Just out of curiosity to see if was possible, I posted the question. So I am not looking for alternatives, I just want to know if it is possible to do what the example code a gave in my original quesion is attempting to do. (Keeping in mind that the custom tag
performs the following code:

<cfset "Caller.#Attributes.r_stOutput#" = myStruct>

It must not be aware of whether it is stuffing "myStruct" into and array or a structure or a list or whatever.)

   If someone can give me a definite "No, that's not possible" or a "Yes, it is possible and here's how you do it..." answer they will be awarded the points.

As to using the Evaluate() function:
  I have not yet had opportunity or the neccesity to get well aquainted with the evaluate(), DE(), or IIF() Funtions. I have read the cfstudio help on them and kind of undertstand the basic concepts but have not successfully used them for any thing yet. If you could show me how to use it in this situation succesfully, I will award you the points.

0
 
LVL 4

Accepted Solution

by:
CF_Spike earned 300 total points
ID: 6215743
ok,

You can't do what you want to do specifically because ColdFusion doesn't allow [] to appear in variable names and it doesn't allow you to use a complex data type as the dynamic part of a variable declaration such as:

<cfset "myvar.#someothervar#" = "junk">

If you wanted to do the same thing where the dynamic part was a structure you should be able to do that fine because you can use dot notation which is valid for variable names.

For example:

Calling page:

<CFSET myStruct = StructNew()>


<cf_ReturnSomething
     r_stOutput = "myStruct.key1"
>

<CFLOOP COLLECTION="#myStruct.Key1#" ITEM="i">
<CFOUTPUT>#myStruct.key1[i]#</CFOUTPUT>
</CFLOOP>

Custom Tag:

<cfset myStruct = StructNew()>
<cfset myStruct.junk = 2>
<cfset "Caller.#Attributes.r_stOutput#" = myStruct>

This should output the value 2.

Spike
0
 
LVL 14

Author Comment

by:Scott Bennett
ID: 6215797
Thank you very much, cf_Spike, you have satisfied my curiosity.

-Scott
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question