• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Excel & AppleScripting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Excel & AppleScripting


  • Subject: Re: Excel & AppleScripting
  • From: "Stockly, Ed" <email@hidden>
  • Date: Mon, 8 Feb 2010 10:46:40 -0800
  • Thread-topic: Excel & AppleScripting

The not-equal sign character in the previous version was replaced with ' in
the email.

This version avoids that issue.


>> FYI, I have a pure  AppleScript version somewhere that converts numbers to
> words.
>
> As promised:
>
> ------------
set numberList to {1, 12, 15, 26, 308, 1234, 1568, 1776, 2010}
set wordList to {}
repeat with thisNumber in numberList
 set thisWord to NumberToWords(thisNumber)
 set the end of wordList to thisWord as text
end repeat

set AppleScript's text item delimiters to return

display dialog wordList as text


on NumberToWords(aNum)
 set onesList to {"one", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}
 set tensList to {"ten", "twenty", "thirty", "forty", "fifty", "sixty",
"seventy", "eighty", "ninety"}
 set AppleScript's text item delimiters to ""
 set aNumList to every text item of (aNum as string)
 set aNum to aNum as integer
 if aNum = 0 then
  set numWord to "zero"
  if the (count of aNumList) > 1 then
   set aNumList to the rest of aNumList
   set numWord to {numWord}
   set the end of numWord to NumberToWords(aNumList as string)
  end if
 else if aNum < 20 then
  set numWord to (item aNum of onesList) as string
 else if aNum < 100 then
  set tenNum to (item 1 of aNumList) as integer
  set oneNum to (item 2 of aNumList) as integer
  set numWord to {item tenNum of tensList}
  if oneNum  is not  0 then set the end of numWord to item oneNum of
onesList
 else if aNum < 1000 then
  set hundNum to (item 1 of aNumList) as integer
  set aNumList to the rest of aNumList
  set hundRem to (aNumList as string) as integer
  set numWord to {item hundNum of onesList, "hundred"}
  if hundRem  is not  0 then set the end of numWord to
NumberToWords(hundRem)
 else if aNum < 1100 then
  set numWord to {"one-thousand"}
  set aNumList to the rest of aNumList
  set thouRem to (aNumList as string) as integer
  if thouRem  is not  0 then set the end of numWord to
NumberToWords(thouRem)
 else if aNum < 2000 then
  set thouNum to items 1 thru 2 of aNumList
  set thouNum to (thouNum as string) as integer
  set numWord to {NumberToWords(thouNum)}
  set aNumList to items 3 thru -1 of aNumList
  set the end of numWord to "hundred"
  set AppleScript's text item delimiters to ""
  set thouRem to (aNumList as string) as integer
  if thouRem  is not  0 then set the end of numWord to
NumberToWords(thouRem)

 else if aNum < 10000 then
  set thouNum to item 1 of aNumList
  set aNumList to the rest of aNumList
  set thouNum to (thouNum as string) as integer
  set numWord to {NumberToWords(thouNum)}
  set the end of numWord to "thousand"
  set AppleScript's text item delimiters to ""
  set thouRem to (aNumList as string) as integer
  if thouRem  is not  0 then set the end of numWord to
NumberToWords(thouRem)

 else if aNum < 100000 then
  set thouNum to items 1 thru 2 of aNumList
  set aNumList to items 3 thru -1 of aNumList
  set thouNum to (thouNum as string) as integer
  set numWord to {NumberToWords(thouNum)}
  set the end of numWord to "thousand"
  set AppleScript's text item delimiters to ""
  set thouRem to (aNumList as string) as integer
  if thouRem  is not  0 then set the end of numWord to
NumberToWords(thouRem)
 else if aNum < 1000000 then
  set thouNum to items 1 thru 3 of aNumList
  set aNumList to items 4 thru -1 of aNumList
  set thouNum to (thouNum as string) as integer
  set numWord to {NumberToWords(thouNum)}
  set the end of numWord to "thousand"
  set AppleScript's text item delimiters to ""
  set thouRem to (aNumList as string) as integer
  if thouRem  is not  0 then set the end of numWord to
NumberToWords(thouRem)
 else if aNum < 10000000 then
  set milNum to item 1 of aNumList
  set aNumList to the rest of aNumList
  set milNum to (milNum as string) as integer
  set numWord to {NumberToWords(milNum)}
  set the end of numWord to "million"
  set AppleScript's text item delimiters to ""
  set milRem to (aNumList as string) as integer
  if milRem  is not  0 then set the end of numWord to NumberToWords(milRem)
 else if aNum < 100000000 then
  set milNum to items 1 thru 2 of aNumList
  set aNumList to items 3 thru -1 of aNumList
  set milNum to (milNum as string) as integer
  set numWord to {NumberToWords(milNum)}
  set the end of numWord to "million"
  set AppleScript's text item delimiters to ""
  set milRem to (aNumList as string) as integer
  if milRem  is not  0 then set the end of numWord to NumberToWords(milRem)
 else if aNum ¾ 536870911 then
  --this is the largest integer that does not get displayed as an exponent
  set milNum to items 1 thru 3 of aNumList
  set aNumList to items 4 thru -1 of aNumList
  set AppleScript's text item delimiters to ""
  set milNum to (milNum as string) as integer
  set numWord to {NumberToWords(milNum)}
  set the end of numWord to "million"
  set AppleScript's text item delimiters to ""
  set milRem to (aNumList as string) as integer
  if milRem  is not  0 then set the end of numWord to NumberToWords(milRem)
 else
  set numWord to aNum as string
 end if
 set AppleScript's text item delimiters to "-"
 set numWord to numWord as string
 return numWord
end NumberToWords


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: Excel & AppleScripting (From: "Stockly, Ed" <email@hidden>)

  • Prev by Date: Recording and Exporting Video with QuickTime and AppleScript
  • Next by Date: Re: Excel & AppleScripting
  • Previous by thread: Re: Excel & AppleScripting
  • Next by thread: problem with perform mail action with messages
  • Index(es):
    • Date
    • Thread