Solved

dynamic assignment of variables?

Posted on 2004-09-29
10
133 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

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…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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