Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

spell out numbers 2

Status
Not open for further replies.

PTmon

IS-IT--Management
Mar 8, 2001
284
US
I'm curious if anyone knows an easy way to spell out the number of records returned from a query. What I'm using works, but it seems like there should be an easier way. Here's what I'm doing:
Code:
<cfquery name="qryMyQuery" datasource="MyDataSource">
SELECT *
FROM tblMyTable
ORDER BY MyID
</cfquery>
<cfoutput query="qryMyQuery">
	<cfswitch expression="#qryMyQuery.recordcount#">
	<cfcase value="1"><cfset variables.strNumber = "one"></cfcase>
	<cfcase value="2"><cfset variables.strNumber = "two"></cfcase>
	<cfcase value="3"><cfset variables.strNumber = "three"></cfcase>
	<cfcase value="4"><cfset variables.strNumber = "four"></cfcase>
	<cfcase value="5"><cfset variables.strNumber = "five"></cfcase>
	<cfcase value="6"><cfset variables.strNumber = "six"></cfcase>
	<cfcase value="7"><cfset variables.strNumber = "seven"></cfcase>
	<cfcase value="8"><cfset variables.strNumber = "eight"></cfcase>
	<cfcase value="9"><cfset variables.strNumber = "nine"></cfcase>
	<cfcase value="10"><cfset variables.strNumber = "ten"></cfcase>
	<cfcase value="11"><cfset variables.strNumber = "eleven"></cfcase>
	<cfcase value="12"><cfset variables.strNumber = "twelve"></cfcase>
	<cfcase value="13"><cfset variables.strNumber = "thirteen"></cfcase>
	<cfcase value="14"><cfset variables.strNumber = "fourteen"></cfcase>
	<cfcase value="15"><cfset variables.strNumber = "fifteen"></cfcase>
	<cfcase value="16"><cfset variables.strNumber = "sixteen"></cfcase>
	<cfcase value="17"><cfset variables.strNumber = "seventeen"></cfcase>
	<cfcase value="18"><cfset variables.strNumber = "eighteen"></cfcase>
	<cfcase value="19"><cfset variables.strNumber = "nineteen"></cfcase>
	<cfcase value="20"><cfset variables.strNumber = "twenty"></cfcase>
	<cfdefaultcase><cfabort showerror="a variety of"></cfdefaultcase>
	</cfswitch>
</cfoutput>
Then I output the number in the middle of a paragraph of text describing how many there are.
Thanks,
PT

putting the "new" in "newb".....
 
you could do

<cfset days = arrayNew(1)>
<cfset days[1]="One">
<cfset days[2]="Two">
<cfset days[3]="Three">
and so on....

<cfoutput>
#days[strNumber]#
</cfoutput>

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
I missed your default case
Code:
<cfoutput>
  <cftry>
    #days[strNumber]#
    <cfcatch>
      a variety of
    </cfcatch>
  </cftry>
</cfoutput>

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
see what i get for being in a hurry? lol


Code:
<cfset days = arrayNew(1)>
<cfset days[1]="One">
<cfset days[2]="Two">
<cfset days[3]="Three">
<!--- and so on.... --->
<cfquery name="qryMyQuery" datasource="MyDataSource">
  SELECT   *
  FROM     tblMyTable
  ORDER BY MyID
</cfquery>
<cftry>
  <cfset strNumber = days[qryMyQuery.recordcount]>
  <cfcatch>
    <cfset StrNumber = "a variety of"
  </cfcatch>
</cftry>

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
if you didn't want to use cfcatch you could do

Code:
<cfquery name="qryMyQuery" datasource="MyDataSource">
  SELECT   *
  FROM     tblMyTable
  ORDER BY MyID
</cfquery>
<cfif qryMyQuery.recordCount gt 0>
  <cfset days = arrayNew(1)>
  <cfset days[1]="One">
  <cfset days[2]="Two">
  <cfset days[3]="Three">
  <!--- and so on.... --->

  <cfif qryMyQuery.recordCount lt 21>
    <cfset strNumber = days[qryMyQuery.recordcount]>
  <cfelse>
    <cfset StrNumber = "a variety of">
  </cfif>
<cfelse>
  <cfset strNumber = "none">
</cfif>

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Thanks, that is helpful but not much simpler. I was hoping for a way around typing in all the numbers. Something like the way dateformat works, where you can display month as a number or have it spelled out. That way I can account for however many records might get added.

putting the "new" in "newb".....
 
I don't think that's going to happen, having a dateFormat(now(), "DDDD")-ish function to spit out the name of the number.

simply becasue of the enormity of the scope. name of week or month are simple for MM to do because of the small scope of the names.

something like what you're after would take a good deal of programming for only a few uses. (it isn't commonly asked for)

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
yeah, I kind of figured as much. I do appreciate the time you spent looking at it though :)
pt


putting the "new" in "newb".....
 
It would be pretty easy for MM to include this. Even though the numbers could be huge, they all follow the same logic.

Here is a JS version, just get the logic from that and recreate it in CF:


Wullie

Fresh Look - Quality Coldfusion/Windows Hosting

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
I thought about it after i posted that. I figured it wouldn't be that hard if you look at how many groups of 3 you can make, then drill down. so, yeah it is possible, but i've never myself needed it and don't imagine there is a huge demand for it. Not to say there isn't any, just not a great deal.

Good find Wullie

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top