July 19, 2008
For ColdFusion hosting try HostMySite.com. |
Home /
Groups /
ColdFusion Talk (CF-Talk)
<cfscript> loop versus <cfloop>
I'm having a hard time tracking down the source of an error I'mJason Durham 04/15/08 09:07 A > I'm having a hard time tracking down the source of an error I'mDominic Watson 04/15/08 09:16 A you need to declare "i" via the script approach. cfloop does a basicPatrick Santora 04/15/08 09:17 A Thank you Dominic and Patrick for your suggestions. In both cases, "i"Jason Durham 04/15/08 09:21 A > The version with <cfloop> is the one that's giving me trouble.Dominic Watson 04/15/08 09:29 A The syntax looks correct, what is the error you are getting?Patrick Santora 04/15/08 09:29 A The variable used in the cfloop is an "i", Outlook changed the case ofJason Durham 04/15/08 09:38 A I would check to see what the argument value for CHILDID is prior to usingPatrick Santora 04/15/08 09:44 A I'll have to check again to be 100% sure, but I believe the value is "".Jason Durham 04/15/08 09:46 A Could it be that qNav is not var scoped? i.e.Dominic Watson 04/15/08 09:49 A That was it!! Thanks a bunch!Jason Durham 04/15/08 09:55 A > That was it!! Thanks a bunch!Dominic Watson 04/15/08 09:58 A Oh good catch Dominic!Patrick Santora 04/15/08 09:58 A I spent 5-6 hours trying to find the solution to this problem on my own.Jason Durham 04/15/08 10:03 A just an observation but the index in the <cfloop> doesnt look like an 'i'Richard White 04/15/08 09:31 A I thought that too, but after copying the code from the thread and pastingPatrick Santora 04/15/08 09:34 A didnt think of doing that :)Richard White 04/15/08 10:02 A Provided that i is set to 1 before the for loop (var i = 1;), then yes, theBobby Hartsfield 04/15/08 09:29 A I'm having a hard time tracking down the source of an error I'm receiving from a recursive function. Are these loops identical? <cfloop from="1" to="#qNav.recordCount#" index="I"> ........ </cfloop> for (; i LTE qNav.recordCount; i=i+1) { ......... } > I'm having a hard time tracking down the source of an error I'm > receiving from a recursive function. Are these loops identical? Not quite, the cfscript loop should look like this: for (i=1; i LTE qNav.recordCount; i=i+1) { ......... } Dominic -- Blog it up: http://fusion.dominicwatson.co.uk you need to declare "i" via the script approach. cfloop does a basic declaration for you. the for loop does not. NOTE: if this loop is within a cffunction then ensure you have scoped i correctly (place "var i = 1" above the loop) or (i = 1; i LTE qNav.recordCount; i=i+1) { ......... } -Pat http://patweb99.avatu.com On Tue, Apr 15, 2008 at 6:08 AM, Jas ----- Excess quoted text cut - see Original Post for more ----- Thank you Dominic and Patrick for your suggestions. In both cases, "i" is var scoped just before the loops. The version with <cfloop> is the one that's giving me trouble. Perhaps it's not in the loop syntax. I've gone character by character comparing the rest of the code in each function and they appear identical. you need to declare "i" via the script approach. cfloop does a basic declaration for you. the for loop does not. NOTE: if this loop is within a cffunction then ensure you have scoped i correctly (place "var i = 1" above the loop) or (i = 1; i LTE qNav.recordCount; i=i+1) { ......... } -Pat http://patweb99.avatu.com On Tue, Apr 15, 2008 at 6:08 AM, Jason Durham <jdurham@cti-stl.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- > The version with <cfloop> is the one that's giving me trouble. Is that an 'L' for the cfloop index or an uppercase 'i'? Other than that I'd say we'd need to see more (nothing wrong with the cfloop or scripted loop if i is set before it). Dominic -- Blog it up: http://fusion.dominicwatson.co.uk The syntax looks correct, what is the error you are getting? On Tue, Apr 15, 2008 at 6:22 AM, Jas ----- Excess quoted text cut - see Original Post for more ----- The variable used in the cfloop is an "i", Outlook changed the case of it automagically. Here is a copy of the function using cfscript syntax that works flawlessly (written by Matt Quackenbush)... http://cfm.pastebin.com/d7595c18e Here is a copy of my re-write using <cfloop>... http://cfm.pastebin.com/m24328359 The error the <cfloop> version results in.... The CHILDID argument passed to the getDepth function is not of type numeric. I've verified that the function works for several iterations but fails on the 4th or 5th time through. They are both using the same external methods [getDepth(),getParent(),getSubs()]. The syntax looks correct, what is the error you are getting? On Tue, Apr 15, 2008 at 6:22 AM, Jason Durham <jdurham@cti-stl.com> wrote: > Thank you Dominic and Patrick for your suggestions. In both cases, "i" > is var scoped just before the loops. > > The version with <cfloop> is the one that's giving me trouble. Perhaps > it's not in the loop syntax. I've gone character by character comparing > the rest of the code in each function and they appear identical. > > you need to declare "i" via the script approach. cfloop does a basic > declaration for you. the for loop does not. > > NOTE: if this loop is within a cffunction then ensure you have scoped i ----- Excess quoted text cut - see Original Post for more ----- I would check to see what the argument value for CHILDID is prior to using getDepth and make sure it is numeric. Your answer might be there. I believe the variable you want to verify is "qNav[getChildOfField()][i]". On Tue, Apr 15, 2008 at 6:39 AM, Jas ----- Excess quoted text cut - see Original Post for more ----- I'll have to check again to be 100% sure, but I believe the value is "". I would check to see what the argument value for CHILDID is prior to using getDepth and make sure it is numeric. Your answer might be there. I believe the variable you want to verify is "qNav[getChildOfField()][i]". On Tue, Apr 15, 2008 at 6:39 AM, Jason Durham <jdurham@cti-stl.com> wrote: > The variable used in the cfloop is an "i", Outlook changed the case of ----- Excess quoted text cut - see Original Post for more ----- scoped ----- Excess quoted text cut - see Original Post for more ----- Could it be that qNav is not var scoped? i.e. <cfset qNav = getSubs(ARGUMENTS.ParentID) /> If this a recursive function, that should break it. Dominic -- Blog it up: http://fusion.dominicwatson.co.uk That was it!! Thanks a bunch! Could it be that qNav is not var scoped? i.e. <cfset qNav = getSubs(ARGUMENTS.ParentID) /> If this a recursive function, that should break it. Dominic -- Blog it up: http://fusion.dominicwatson.co.uk > That was it!! Thanks a bunch! Hoorah! No worries ;) D -- Blog it up: http://fusion.dominicwatson.co.uk Oh good catch Dominic! On Tue, Apr 15, 2008 at 6:50 AM, Dominic Watson < watson.dominic@googlemail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- I spent 5-6 hours trying to find the solution to this problem on my own. *embarrassed* I *hope* not to make that mistake again! Var first... ask questions later. :) Oh good catch Dominic! On Tue, Apr 15, 2008 at 6:50 AM, Dominic Watson < watson.dominic@googlemail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- just an observation but the index in the <cfloop> doesnt look like an 'i' my eyes may be playing me up though!!! I thought that too, but after copying the code from the thread and pasting it into my local environment showed it is being a capital "i". On Tue, Apr 15, 2008 at 6:32 AM, Richard White <richard@j7is.co.uk> wrote: > just an observation but the index in the <cfloop> doesnt look like an 'i' > > my eyes may be playing me up though!!! didnt think of doing that :) ----- Excess quoted text cut - see Original Post for more ----- Provided that i is set to 1 before the for loop (var i = 1;), then yes, the loops are identical .:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com I'm having a hard time tracking down the source of an error I'm receiving from a recursive function. Are these loops identical? <cfloop from="1" to="#qNav.recordCount#" index="I"> ........ </cfloop> for (; i LTE qNav.recordCount; i=i+1) { ......... }
|
Mailing Lists
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||