Re: cfscript looping over udf's

2005-06-23 Thread Sean Corfield
On 6/23/05, Brian Holder [EMAIL PROTECTED] wrote:
 function DrawRow(someNo, someAmt) {
 
   var rRow = ;
   var thisRow = SetValue(someNo, someAmt);
 
   for( i = 1; i lte ArrayLen(thisRow); i = i+1 ) {

You forgot to var-declare i
-- 
Sean A Corfield -- http://corfield.org/
Team Fusebox -- http://fusebox.org/
Got Gmail? -- I have 50, yes 50, invites to give away!

If you're not annoying somebody, you're not really alive.
-- Margaret Atwood

~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:210383
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=11502.10531.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: cfscript looping over udf's

2005-06-23 Thread Ian Skinner
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


Re: cfscript looping over udf's

2005-06-23 Thread S . Isaac Dealey
You didn't declare i in DrawRow() with the var keyword -- that's your
problem, since it's overwriting the variable i you're using to loop
over the query...

I also I don't see aRow declared anywhere... i.e. aRow =
arrayNew(1)... don't know if that's a problem...

And your setValue function could be shorter:

function SetValue(someNo, someAmt) {
  switch (someNo) {
case 082: { ; }
case 126: { ; }
case 153: { ; }
case 176: { ; }
case 301: { ; }
  aRow[5] = someAmt;
  break;
}
  }
  return aRow; // return an array
}


s. isaac dealey   954.522.6080
new epoch : isn't it time for a change?

add features without fixtures with
the onTap open source framework

http://www.fusiontap.com
http://coldfusion.sys-con.com/author/4806Dealey.htm




~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:210386
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=11502.10531.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


Re: cfscript looping over udf's

2005-06-23 Thread Raymond Camden
Your UDF uses the loop variable, i. So does your main page call. You
forgot to var scope the i in the UDF. That's the problem.

On 6/23/05, Brian Holder [EMAIL PROTECTED] wrote:
 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])));
 } 


-- 
===
Raymond Camden, Director of Development for Mindseye, Inc (www.mindseye.com)

Member of Team Macromedia (http://www.macromedia.com/go/teammacromedia)

Email: [EMAIL PROTECTED]
Blog : ray.camdenfamily.com
Yahoo IM : cfjedimaster

My ally is the Force, and a powerful ally it is. - Yoda

~|
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:210387
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


Re: cfscript looping over udf's

2005-06-23 Thread Brian Holder
You didn't declare i in DrawRow() with the var keyword -- that's your
problem, since it's overwriting the variable i you're using to loop
over the query...

duh - thanks everyone - i just changed the i to var j for more clarity and it 
works perfectly with the following code...

for( i = 1; i lte qQuery.RecordCount; i = i+1 ) {
  WriteOutput(DrawRow(qQuery.colA[i]), Trim(qQuery.colB[i])));
}

function DrawRow(someNo, someAmt) {

  var j = 0;
  var rRow = ;
  var thisRow = SetValue(someNo, someAmt);

  for( j = 1; j lte ArrayLen(thisRow); j = j+1 ) {
rRow = rRow  'td align=right class='  IIf(thisRow[j] lt 0, 
DE(negative), DE())  '';
rRow = rRow  IIf(thisRow[i] gt 0, DE(DecimalFormat(thisRow[j])), 
DE(nbsp;))  '/td';
  }
  return rRow;  // return a string
}

function SetValue(someNo, someAmt) {

  var aRow = ArrayNew(1);
  ArraySet(aRow, 1, 5, 0);
  
  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
}

~|
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:210409
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=11502.10531.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54