Solved

dynamic assignment of variables?

Posted on 2004-09-29
10
132 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
10 Comments
 
LVL 35

Accepted Solution

by:
mrichmon earned 50 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now