you could try:
 
 
<cffunction name="arrayPositionValues" access="public" returntype="any" 
                description="I take in 2 numbers and find the values in the 
columnListArr"> 
        <cfargument name="startPoint" type="numeric" required="false" 
default="1">
        <cfargument name="endPoint" type="numeric" required="false" 
default="#arrayLen(variables.columnListArr)#">            

        <cfscript>
          var aReturnArray = arrayNew(1);
           var iCount = 0;
 
          //let make sure we don't have an argument to is to large....
          if(arguments.endPoint GT arrayLen(variables.columnListArr))  
arguments.endPoint = arrayLen(variables.columnListArr);
 
          for(iCount = arguments.startPoint; iCount LTE arguments.endPoint; 
iCount = iCount + 1){
               arrayAppend(aReturnArray,variables.columnListArr[iCount]);
          }
 
       </cfscript>
 
        <cfreturn aReturnArray>        
    </cffunction>
 
I may be miss understanding this, but I am not sure why you are using the 
ArrayLen function in your from and to values, as you are not interested in the 
length of the array, only where you are starting and finishing, which is 
provided via arguments...
Also a couple of un-vared variables, which can lead to unexpected behaviour 
depending on how/when the function is being called.
The 2 variables that need to be vared are "MyNewArray" and "x"
 
Also a good idea to provide defaults to you arguments if they are not requried.
 
The function I wrote won't error if you feed in the argument "endPoint" larger 
than the array length. You could put something to catch if the start point is 
wrong too.
 
I havn't tested this code, and only writen it here.
 
Good luck and I HTH
 
Have a good week end,
 
David

 
________________________________

From: [EMAIL PROTECTED] on behalf of Stephen Adams
Sent: Fri 24/02/2006 11:16 p.m.
To: cfcdev
Subject: [CFCDev] Looping between to points of an array


Hi,

I'm trying to create a cffunction where I can dynamically loop between to 
points of an array. For example I may want to be able to loop from point 1 of 
the array to point 10. Then I may want to loop from point 11 to point 20 of the 
same array. 

I've written a function to do this, which looks like this:

<cffunction name="arrayPositionValues" access="public" returntype="any" 
                description="I take in 2 numbers and find the values in the 
columnListArr"> 
        <cfargument name="startPoint" type="numeric" required="false" />
        <cfargument name="endPoint" type="numeric" required="false" />          
  

        <cfset MyNewArray = ArrayNew(1)>
        <cfloop index="x" 
from="#ArrayLen(variables.columnListArr[startPoint])#" 
to="#ArrayLen(variables.columnListArr[endPoint])#"> 
            <!--- build array --->
            <cfset #ArrayAppend(MyNewArray, x)#>
        </cfloop>
        
        <!--- return sub section of array --->
        <cfreturn MyNewArray /> 
        
    </cffunction>

In this I am creating a sub section of a larger array based on the two points 
being passed into the function. Unfortunately I can't seem to get the loop to 
loop between the two points that I'm passing in. 

Can anyone suggest a better way to do this?

Thanks

Stephen
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
cfcdev@cfczone.org with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/cfcdev@cfczone.org 

#####################################################################################

This email has been scanned by MailMarshal, an email content filter. 

#####################################################################################



----------------------------------------------------------

You are subscribed to cfcdev. To unsubscribe, send an email to 
cfcdev@cfczone.org with the words 'unsubscribe cfcdev' as the subject of the 
email.



CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).



An archive of the CFCDev list is available at 
www.mail-archive.com/cfcdev@cfczone.org

<<winmail.dat>>

Reply via email to