CFLib.org – Common Function Library Project

CreateOrderedList(st, end[, step][, delim])

Last updated September 28, 2006

author

Mike Gillespie

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
Pass in Start and End numbers (with options for delim and step increment) and this UDF will generate an Ascending (or descending), ordered delimited list in your step increment.

Return Values:
Returns a string.

Example:

<cfoutput>
Basic: #CreateOrderedList(1,10)#<br>
Step Down: #createOrderedList(0,-25,5,"|")#
</cfoutput>

Parameters:

Name Description Required
st Start number. Yes
end End number. Yes
step Step value. Defaults to 1. No
delim List delimiter. Defaults to a comma. No

Full UDF Source:

/**
 * Used to create an Ordered Numeric List
 * v2 mods by Raymond Camden
 * 
 * @param st      Start number. (Required)
 * @param end      End number. (Required)
 * @param step      Step value. Defaults to 1. (Optional)
 * @param delim      List delimiter. Defaults to a comma. (Optional)
 * @return Returns a string. 
 * @author Mike Gillespie (mike@striking.com) 
 * @version 1, September 28, 2006 
 */
function createOrderedList(st,end) {
    var theList="";
    var delim=",";
    var step=1;

    // 3rd argument sets the step increment
    if(arraylen(arguments) gte 3) step=arguments[3];

    //4th argument sets the delim
    if(arraylen(arguments) eq 4) delim=arguments[4];

    if(st gte end) for(i = st;i gte end;i=i-step) theList=listappend(theList,i,delim);        
    else for(i = st;i lte end;i=i+step) theList=listappend(theList,i,delim);        

    return theList;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson