Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CF range?? 1

Status
Not open for further replies.

GUJUm0deL

Programmer
Jan 16, 2001
3,676
US
Hiya folks, need some help here. I want to print a number in a range in a report. I tried using <cfloop> but that didn't work, what other way is there??

This is what I tried:
Code:
<cfloop index="name1" from="4471" to="4480">
  <cfset name1 = name1>
</cfloop>
...
...
...
<cffile="write" output="#name1##fname##lname##address#">

But that prints the number: 4481, why??

What I want is "name1" to print 4471 then print the fname, lname and address...then print 4472 then fname, lname and address...all the way to 4480.

What am I doing wrong??

PS:
I also tried
Code:
<cfloop index="name1" from="4471" to="4480">
  <cfset name1 = name1[COLOR=red]+1[/color]>
</cfloop>

Got the same results.

[sub]
____________________________________
Just Imagine.
[sub]
 
where are you getting the data from.

if you are looping over numbers where are you getting fname,lname, and address from.... how are you going to put them together....

More details please..

------------------------------------------------------------------------------
brannonH
if( !succeed ) try( );
 
bhightower, all other data is coming from the dB, the form prior to this is collecting the data, and this form just creates a textfile with the data in it.

I get it all to work just fine except this...

Thanks.

[sub]
____________________________________
Just Imagine.
[sub]
 
To answer the question, "What am I doing wrong?"; You are calling the name1 var AFTER the loop. Remember that the <cffile ...> line doesn't get fired until the <cfloop ..> is completely finished.

Here's a quick example of what your code is doing:

First iteration of loop:
<cfset name1 = 4471>

Second iteration of loop:
<cfset name1 = 4472>

Third iteration of loop:
<cfset name1 = 4473>
.
.
.
.
Last iteration:
<cfset name1 = 4480>

Now that the loop is finished, cfas processes the <cffile .. tag>

Note that <cffile ...> doesn't fire until after the last iteration of the loop.

When cfas evaluates "#name1##fname##lname##address#", the name1 value will be equal to the value that the last iteration of your loop created.

You have to trap the value for name1 in each iteration.

Example:

<cfset myOutput="">
<cfloop index="name1" from="4471" to="4480">
<cfset myOutput = "#name1##fname##lname##address#" & chr(13) & chr(10) & myOutput>
</cfloop>
...
<cffile="write" output="#myOutput#">
 
tooled, hmmmm, that makes sense. Thanks for the easy rundown.

You get a star...

[sub]
____________________________________
Just Imagine.
[sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top