[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

dynamic assignment of variables?

Posted on 2004-09-29
10
Medium Priority
?
142 Views
Last Modified: 2013-12-24
Is this possible I need variables for the amount of weeks between startweeks and endweeks (t01, t02, t03, t04)

<cfloop index="j3" from="#startweek#" to="#endweek#" step="1">
<cfset 't'&j3 = 0>
</cfloop>

john
0
Comment
Question by:jcorbin
  • 4
  • 3
8 Comments
 
LVL 35

Accepted Solution

by:
mrichmon earned 200 total points
ID: 12185450
Like this :

<cfset Variables['t' & j3] = 0>

Or for form variables use :

<cfset Form['t' & j3] = 0>

Or for URL variables or session variables do similarly...
0
 
LVL 7

Expert Comment

by:INSDivision6
ID: 12186630
Something like this using Evaluate():


<html><body>

<!--- Create and assign --->
<cfloop index="i" from="1" to="10">
   <cfset Evaluate("t#NumberFormat(i, '00')#=i")>
</cfloop>

<!--- Test them --->
<cfoutput>t01=#t01#</cfoutput><br>
<cfoutput>t02=#t02#</cfoutput><br>
<cfoutput>t03=#t03#</cfoutput><br>
<cfoutput>t04=#t04#</cfoutput><br>
<cfoutput>t05=#t05#</cfoutput><br>
<cfoutput>t06=#t06#</cfoutput><br>
<cfoutput>t07=#t07#</cfoutput><br>
<cfoutput>t08=#t08#</cfoutput><br>
<cfoutput>t09=#t09#</cfoutput><br>
<cfoutput>t10=#t10#</cfoutput><br>

</body></html>
0
 
LVL 10

Expert Comment

by:Mause
ID: 12187399
Hi there,

I would just do something like this:

<cfloop index="j3" from="#startweek#" to="#endweek#" step="1">
   <cfset 't#j3#' = 0>
</cfloop>

and if you want session variables:
<cfset 'session.t#j3#' = 0>

INSDivision try to avoid 'evaluate' because its slow esspecialy in loops!
You can also use cfdump to see all the variables: <cfdump var="#variables#"> or <cfdump var="#sessions#">

Mause
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
LVL 35

Expert Comment

by:mrichmon
ID: 12191531
Mause - you are correct that evaluate is slow, but so is using # the way you showed.

Really the only efficient method is accessing it from teh scope as in my example.
0
 
LVL 10

Expert Comment

by:Mause
ID: 12191943
mrichmon - I just run a test width your code and mine
and indeed yours is faster (in a loop of 1000) but its only 5 to 10ms :)


0
 
LVL 35

Expert Comment

by:mrichmon
ID: 12191975
There is also another advantage.

The scope syntax (the method I showed) works in every situation I have come across so far.

I used to use your method or the evaluate until I found that in some complex situations it actually doesn't work and the only way to actually work is to use the scope syntax.
0
 
LVL 10

Expert Comment

by:Mause
ID: 12192041
mrichmon your code is great and I have to admit that even I use it is some situation
Lets say I only showed an ohter way how to do it

0
 
LVL 35

Expert Comment

by:mrichmon
ID: 12192880
Yep

I wasn't criticizing your way... I used it quite a lot until I found this scope method.

:o)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
What You Need to Know when Searching for a Webhost Provider
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

872 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