Solved

Custom Tag Question

Posted on 2001-06-20
4
278 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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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…

734 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