This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Shayne

By: a guest on Dec 11th, 2007  |  syntax: ColdFusion  |  size: 3.56 KB  |  views: 449  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <cfcomponent output="false">
  2.     <cfscript>
  3.         this.COUNTUP   = 1;
  4.         this.COUNTDOWN = 0;
  5.        
  6.         instance           = StructNew();
  7.         instance.delimiter = "";
  8.         instance.direction = 1;
  9.         instance.endNum    = 0;
  10.         instance.startNum  = 0;
  11.     </cfscript>
  12.    
  13.     <cffunction name="init" output="false" access="public">
  14.         <cfargument name="startNum" required="true" />
  15.         <cfargument name="endNum" required="true" />
  16.         <cfargument name="direction" default="-1" />
  17.         <cfscript>
  18.             setStartNum(arguments.startNum);
  19.             setEndNum(arguments.endNum);
  20.            
  21.             if (arguments.direction EQ -1) {
  22.                 if (arguments.startNum LTE arguments.endNum) {
  23.                     setCountUp();
  24.                 } else {
  25.                     setCountDown();
  26.                 }
  27.             } else {
  28.                 setDirection(arguments.direction);
  29.             }
  30.         </cfscript>
  31.         <cfreturn this />
  32.     </cffunction>
  33.    
  34.     <cffunction name="run" output="false" access="public">
  35.         <cfscript>
  36.             var output = "";
  37.             var i      = 0;
  38.             var start  = getStartNum();
  39.             var end    = getEndNum();
  40.             var doAbs  = false;
  41.            
  42.             if (getEndNum() LTE getStartNum()) {
  43.                 start = start * -1;
  44.                 end   = end * -1;
  45.             }
  46.            
  47.             for (i=start; i LTE end; i++) {
  48.                 output &= IIf(doAbs, Abs(i), i);
  49.                 if (hasDelimiter() AND i LT end) {
  50.                     output &= getDelimiter();
  51.                 }
  52.             }
  53.         </cfscript>
  54.         <cfreturn output />
  55.     </cffunction>
  56.    
  57.     <!--- Getters/Setters --->
  58.    
  59.     <cffunction name="getDirection" output="false" access="public">
  60.         <cfreturn instance.direction />
  61.     </cffunction>
  62.    
  63.     <cffunction name="setDirection" output="false" access="public">
  64.         <cfargument name="direction" required="true" />
  65.         <cfset instance.direction = arguments.direction />
  66.     </cffunction>
  67.    
  68.     <cffunction name="getEndNum" output="false" access="public">
  69.         <cfreturn instance.endNum />
  70.     </cffunction>
  71.    
  72.     <cffunction name="setEndNum" output="false" access="public">
  73.         <cfargument name="endNum" required="true" />
  74.         <cfset instance.endNum = arguments.endNum />
  75.     </cffunction>
  76.    
  77.     <cffunction name="hasDelimiter" output="false" access="public">
  78.         <cfreturn StructKeyExists(instance, "delimiter") AND Len(instance.delimiter) GT 0 />
  79.     </cffunction>
  80.    
  81.     <cffunction name="getDelimiter" output="false" access="public">
  82.         <cfreturn instance.delimiter />
  83.     </cffunction>
  84.    
  85.     <cffunction name="setDelimiter" output="false" access="public">
  86.         <cfargument name="delimiter" required="true" />
  87.         <cfset instance.delimiter = arguments.delimiter />
  88.     </cffunction>
  89.    
  90.     <cffunction name="getStartNum" output="false" access="public">
  91.         <cfreturn instance.startNum />
  92.     </cffunction>
  93.    
  94.     <cffunction name="setStartNum" output="false" access="public">
  95.         <cfargument name="startNum" required="true" />
  96.         <cfset instance.startNum = arguments.startNum />
  97.     </cffunction>
  98.    
  99.     <cffunction name="setCountUp" output="false" access="public">
  100.         <cfset setDirection(this.COUNTUP) />
  101.     </cffunction>
  102.    
  103.     <cffunction name="setCountDown" output="false" access="public">
  104.         <cfset setDirection(this.COUNTDOWN) />
  105.     </cffunction>
  106. </cfcomponent>
clone this paste RAW Paste Data