Solved

dynamic assignment of variables?

Posted on 2004-09-29
10
138 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
[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
  • 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

724 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