CFLib.org – Common Function Library Project

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

Last updated September 28, 2006

Version: 1 | Requires: ColdFusion 5 | Library: UtilityLib

 
Rated 1 time(s). Average Rating: 4.0

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:

view plain print about
<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:

view plain print about
<cfscript>
/**
 * 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;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
11 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
30 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson