19.0 Must Be Within Range: ( 1 : 12 )

Posted July 30, 2007 at 5:18 PM by Ben Nadel

Tags: ColdFusion

I was just helping someone debug a strange ColdFusion error:

19.0 Must Be Within Range: ( 1 : 12 ). ColdFusion cannot determine the line of the template that caused this error. This is often caused by an error in the exception handling subsystem.

Because ColdFusion wasn't giving us any template or line numbers, we basically had to start commenting out code and putting it back in until we narrowed down the template and the line. And, seeing as I was not working on the project, this was particularly necessary (as I was not familiar with the code at all - just called over for the error). Finally, we narrowed it down to the ColdFusion method, MonthAsString(). This takes a month index and returns the name of the month. Therefore, running:

  • #MonthAsString( 1 )#

... gives us:

January

The values, obviously, can only be 1 - 12, as there are only 12 months in the year. As it turns out, there was some weird math algorithm that was passing a variable of the value 19 to the MonthAsString() function; hence the whole out of range error.

Good to know if I ever see this error again.



Reader Comments

Jul 31, 2007 at 12:49 AM // reply »
3 Comments

When I was a kid I ran across a few page insert in a day planner that had a system to calculate the day of week (Monday, Thursday, etc.) of any date between around 1500 and 2100. Years later I realized it was based on an algorithm that works for our current calendar system(Gregorian).

I suspect the 19 is a remnant of the formula. The days of week fall on a fairly predictable basis for hundreds of years based on a relatively easy formula.

http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week
http://www.jimloy.com/math/day-week.htm


Nic
Aug 3, 2007 at 12:41 PM // reply »
1 Comments

Cool


Nov 3, 2009 at 2:43 PM // reply »
9 Comments

I recently had a similar ColdFusion error with no line number information to help:
11.0 must be within range: ( 1 : 7 )

The date in my Form variable was "11/11/2009" and I was doing this:
DayOfWeekAsString(Day(Form.menu_dt)

After finding this blog entry, I quickly discovered I was out of the range for days in a week and fixed the inner function call:
DayOfWeekAsString(DayOfWeek(Form.menu_dt)


Nov 3, 2009 at 2:57 PM // reply »
10,640 Comments

@Troy,

Yeah, that'll get you ever time :) Good catch.


Ash
Feb 11, 2010 at 10:57 AM // reply »
1 Comments

thanks for sharing this. saved me a lotta time.


Feb 11, 2010 at 10:59 AM // reply »
10,640 Comments

@Ash,

No problem my man.


JC
Aug 31, 2010 at 2:17 PM // reply »
16 Comments

Just hit this one myself, but wasn't having any luck with it.

<cfswitch expression="#dayofweek(now())#">
<cfcase value="1,7">Weekend</cfcase>
<cfcase value="2">Monday</cfcase>
<cfdefaultcase>Other Day</cfdefaultcase>
</cfswitch>

finally realized... it was because I was outputting #DayOfWeekAsString(NOW())# to get the name of the "Other Day" in some text... As with Troy above, adding dayofweek() into the mix fixed it.

Really strange and unexpected behavior for me.. usually coldfusion is so friendly that it just does that sort of conversion behind the scenes for you.


Sep 3, 2010 at 10:42 PM // reply »
10,640 Comments

@JC,

Yeah, especially with dates - you can throw just about anything at ColdFusion and, chances are, it can convert it to a date :)


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Feb 10, 2012 at 7:21 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
Update! Instead of $(eval(options.insertAfter)).after(data['insertData']); I now use: var ajaxNode = document.createElement('span'); var parent = $(eval(options.insertAfter))[0].parentNode; ... read »
Feb 10, 2012 at 6:18 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
encountered this same, what I consider, jQuery bug last week. I'm building a site in which I load some content via AJAX. This content contains Linkedin share button placeholders which Linkedin API ne ... read »
Feb 10, 2012 at 11:30 AM
Cross-Origin Resource Sharing (CORS) AJAX Requests Between jQuery And Node.js
After you understand the concepts here, this is an awesome cheatsheet for enabling CORS in just about anything http://enable-cors.org/ ... read »
JM
Feb 10, 2012 at 9:10 AM
My Safari Browser SQLite Database Hello World Example
@Amy, Here is a very good tutorial on how to use JOIN: http://www.sqltutorial.org/sqljoin-innerjoin.aspx ... read »
Feb 10, 2012 at 4:42 AM
Building A Twitter-Inspired RESTful API Architecture In ColdFusion
This is great, very useful Ben. I spotted a small typo in the api.cgm listing: <cfthrow type="Unauthroized" /> Cheers Stefan ... read »
Feb 9, 2012 at 10:35 PM
CFDirectory Filtering Uses Pipe Character For Multiple Filters (Thanks Steve Withington)
I was wondering if there would be a filter you could apply so that you got everything but what you included in the filter. As in show me all docs that are not a .pdf. ... read »
Feb 9, 2012 at 10:29 PM
Learning ColdFusion 9: Application-Specific Data Sources
@Ben, No offence, but if people were really wanting advanced features they would be using a platform like ASP.NET MVC. CFML is so structurally compromised as a tag-based scripting language that ... read »
Feb 9, 2012 at 10:03 PM
Subversion - Cleanup Failed To Process The Following Paths
@Leviaguirre, do you still have problems with this? ... read »