You need to var scope the 'i' variable in the function so it is local to the 
function, otherwise it is the same 'i' in the main loop thus funky, 
unintentional results occur.  Scope those variables! 


--------------
Ian Skinner
Web Programmer
BloodSource
www.BloodSource.org
Sacramento, CA
 
"C code. C code run. Run code run. Please!"
- Cynthia Dunning

....-----Original Message-----
....From: Brian Holder [mailto:[EMAIL PROTECTED]
....Sent: Thursday, June 23, 2005 9:27 AM
....To: CF-Talk
....Subject: cfscript looping over udf's
....
....i am looping over a query - inside the loop, i am calling a udf that
....calls another udf...
....
....for( i = 1; i lte qQuery.RecordCount; i = i+1 ) {
....  WriteOutput(DrawRow(qQuery.colA[i]), Trim(qQuery.colB[i])));
....}
....
....function DrawRow(someNo, someAmt) {
....
....  var rRow = "";
....  var thisRow = SetValue(someNo, someAmt);
....
....  for( i = 1; i lte ArrayLen(thisRow); i = i+1 ) {
....    rRow = rRow & '<td align="right" class="' & IIf(thisRow[i] lt 0,
....DE("negative"), DE("")) & '">';
....    rRow = rRow & IIf(thisRow[i] gt 0, DE(DecimalFormat(thisRow[i])),
....DE("&nbsp;")) & '</td>';
....  }
....  return rRow;  // return a string
....}
....
....function SetValue(someNo, someAmt) {
....  switch (someNo) {
....    case "082": {
....      aRow[1] = someAmt;
....      break;
....    }
....    case "126": {
....      aRow[2] = someAmt;
....      break;
....    }
....    case "153": {
....      aRow[3] = someAmt;
....      break;
....    }
....    case "176": {
....      aRow[4] = someAmt;
....      break;
....    }
....    case "301": {
....      aRow[5] = someAmt;
....      break;
....    }
....  }
....  return aRow; // return an array
....}
....
....however, the call to the DrawRow() udf in the query loop works for the
....first iteration, then breaks out of the loop therfore ignoring any
....subsequent records.
....
....does anyone see a possible reason for this?
....
....at first i thought it maybe the use of break in the case statements in
....the SetValue udf, so i changed to using if/else if, but that produced the
....same results.
....
....i also tried using global variables instead of function-local vars for
....the array - still no luck.
....
....it really seems as though something wacked is happening after the first
....iteration of the query loop that is causing the loop to end prematurely,
....but i can seem to pin it down.
....
....this is in cf5 btw <cringe>
....
....tia!
....
....

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:210381
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to