ok well after I sent it I felt bad I didn't do at least minimal testing so I tested it, found 3 bugs! and fixed them .. here is the revised version sorry:
<cffunction name="ArrayMid" returntype="array" output="false" hint="returns a subsection of an array"> <cfargument name="inArray" type="array" required="true" /> <cfargument name="startPos" type="numeric" required="true" /> <cfargument name="count" type="numeric" required="false" default="#ArrayLen(arguments.inArray) - arguments.startPos#" /> <cfset var outArray = ArrayNew(1) /> <cfset var i = 0 /> <cfset var maxPosition = arrayLen(arguments.inArray) /> <cfif MaxPosition> <!--- make sure the startPosition is a positive integer ---> <cfif arguments.startPos LTE 0> <cfset arguments.startPos = 1 /> </cfif> <!--- make sure we aren't starting at too high of a position ---> <cfif arguments.startPos GT maxPosition> <cfset arguments.startPos = maxPosition /> </cfif> <!--- make sure we won't go beyond the bounds of the array ---> <cfif arguments.count + arguments.startPos GT maxPosition> <cfset arguments.count = ArrayLen(arguments.inArray) - arguments.startPos /> </cfif> <!--- deal with case where only the last element is desired ---> <cfif arguments.startPos EQ MaxPosition> <cfset ArrayAppend(outArray,arguments.inArray[maxPosition]) /> </cfif> <!--- get the "subArray" ---> <cfloop from="#arguments.startPos#" to="#arguments.startPos + arguments.count-1#" index="i"> <cfset ArrayAppend(outArray,arguments.inArray[i]) /> </cfloop> </cfif> <cfreturn outArray /> </cffunction> ---------------------------------------------------------- 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