Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Replace Numbers with Text


  • Please log in to reply
1 reply to this topic
Szara
  • Members
  • 8 posts
  • Last active: Jul 01 2006 07:46 AM
  • Joined: 24 Jun 2006
As a bookkeeper, I write a lot of cheques in Excel, and I got tired typing out the entire amount every time. So I wrote myself this script, which does that hard work for me. Figured someone else might find it handy.

Some limitations:
- I never figured out how to get it to save the values to the clipboard, so it writes the variables directly into the active program immediately;
- Numbers have to be entered backwards, as I couldn't figure out how to get it to sense how many digits there were and output accordingly.

Plenty of other limitations, I'm sure, but if it's of use to someone, then I'll be pleased. I had fun figuring it all out.
; Number Replacement script - Replace any number with that number written in text.
; by Anna Hill/Szara

Menu, Tray, Icon, C:\Program Files\AutoHotkey\Icons\iicon.ico ;Icon in the tray just because I like to have them there when a script is running.  You're welcome to remove it.

#SingleInstance, force


Gui, Add, Edit, x5 y18 w15 number limit1 gNext vCent2
Gui, Add, Edit, x20 y18 w15 number limit1 gNext vCent1
Gui, Add, Edit, x35 y18 w15 number limit1 gNext vOnes
Gui, Add, Edit, x50 y18 w15 number limit1 gNext vTens
Gui, Add, Edit, x65 y18 w15 number limit1 gNext vHunds
Gui, Add, Edit, x80 y18 w15 number limit1 gNext vThous
Gui, Add, Edit, x95 y18 w15 number limit1 gNext vTThous
Gui, Add, Edit, x110 y18 w15 number limit1 gNext vHThous


Gui,Add,Button, x175 y18 default,OK ;
; Gui,Add,Button, x35 y50 w30 Reload,Reload ;I used this button a lot when testing, but found it unnecessary once the script worked
; Gui,Add,Button, x80 y50 w30 Cancel,Cancel ;Ditto
Gui,Show

return

Next:	; a "g" label with the above which moves cursor to the next entry box immediately
Send `t
return

ButtonReload:
Reload

ButtonOK:
Gui,Submit ; Save each control's contents to its associated variable.
Send #n ;it's set up so that the command to output the text will execute immediately; I'm not sure how to change this to write the result to clipboard
return

GuiEscape:
GuiClose:
ButtonCancel:
Gui, Cancel  ; All of the above labels will execute this subroutine.
return

#n::
Send %HThous%%TThous%%Thous%%Hunds%%Tens%%Ones%.%Cent1%%Cent2%  ; to send the number in numerals
;Send +`t+`t+`t+`t+`t+`t+`t+`t+`t  ; put here any commands to perform between the numerals and text
If HThous > 0
Gosub t_HThous
If TThous > 0
Gosub t_TThous
If Thous > 0
Gosub t_Thous
If Hunds > 0
Gosub t_Hunds
If Tens > 0
Gosub t_Tens
Gosub t_Ones
Send and %Cent1%%Cent2% ; in my case I needed to send the cents as numbers
; Send `n+`t+`t+`t{ctrl down}{up}{ctrl up}{down} ; put here any commands to perform after sending the text
ExitApp


t_HThous:
{	
	If HThous = 1
		Send One hundred{space}
	If HThous = 2
		Send Two hundred{space}
	If HThous = 3
		Send Three hundred{space}
	If HThous = 4
		Send Four hundred{space}
	If HThous = 5
		Send Five hundred{space}
	If HThous = 6
		Send Six hundred{space}
	If HThous = 7
		Send Seven hundred{space}
	If HThous = 8
		Send Eight hundred{space}
	If HThous = 9
		Send Nine hundred{space}
}
return

t_TThous:
If Thous > 0
Gosub d_TThous
else
{	
	If TThous = 0
		return
	If TThous = 1
		Gosub t_TeenThous
	If TThous = 2
		Send Twenty{space}
	If TThous = 3
		Send Thirty{space}
	If TThous = 4
		Send Forty{space}
	If TThous = 5
		Send Fifty{space}
	If TThous = 6
		Send Sixty{space}
	If TThous = 7
		Send Seventy{space}
	If TThous = 8
		Send Eighty{space}
	If TThous = 9
		Send Ninety{space}
}
return

d_TThous:
{	
	If TThous = 0
		Return
	If TThous = 1
		Gosub t_TeenThous
	If TThous = 2
		Send Twenty-
	If TThous = 3
		Send Thirty-
	If TThous = 4
		Send Forty-
	If TThous = 5
		Send Fifty-
	If TThous = 6
		Send Sixty-
	If TThous = 7
		Send Seventy-
	If TThous = 8
		Send Eighty-
	If TThous = 9
		Send Ninety-
}
return


t_TeenThous:
{	
	If Thous = 0
		Send Ten Thousand{space}
	If Thous = 1
		Send Eleven Thousand{space}
	If Thous = 2
		Send Twelve Thousand{space}
	If Thous = 3
		Send Thirteen Thousand{space}
	If Thous = 4
		Send Fourteen Thousand{space}
	If Thous = 5
		Send Fifteen Thousand{space}
	If Thous = 6
		Send Sixteen Thousand{space}
	If Thous = 7
		Send Seventeen Thousand{space}
	If Thous = 8
		Send Eighteen Thousand{space}
	If Thous = 9
		Send Nineteen Thousand{space}
}
return


t_Thous:
{	
	If TThous = 1
		return	
	If Thous = 0
		return
	If Thous = 1
		Send One Thousand{space}
	If Thous = 2
		Send Two Thousand{space}
	If Thous = 3
		Send Three Thousand{space}
	If Thous = 4
		Send Four Thousand{space}
	If Thous = 5
		Send Five Thousand{space}
	If Thous = 6
		Send Six Thousand{space}
	If Thous = 7
		Send Seven Thousand{space}
	If Thous = 8
		Send Eight Thousand{space}
	If Thous = 9
		Send Nine Thousand{space}
}
return


t_Hunds:
{	
	If Hunds = 0
		return
	If Hunds = 1
		Send One Hundred{space}
	If Hunds = 2
		Send Two Hundred{space}
	If Hunds = 3
		Send Three Hundred{space}
	If Hunds = 4
		Send Four Hundred{space}
	If Hunds = 5
		Send Five Hundred{space}
	If Hunds = 6
		Send Six Hundred{space}
	If Hunds = 7
		Send Seven Hundred{space}
	If Hunds = 8
		Send Eight Hundred{space}
	If Hunds = 9
		Send Nine Hundred{space}
}
return


t_Tens:
If Ones > 0
Gosub d_Tens
else
{	
	If Tens = 0
		Return
	If Tens = 1
		Gosub t_Teens
	If Tens = 2
		Send Twenty{space}
	If Tens = 3
		Send Thirty{space}
	If Tens = 4
		Send Forty{space}
	If Tens = 5
		Send Fifty{space}
	If Tens = 6
		Send Sixty{space}
	If Tens = 7
		Send Seventy{space}
	If Tens = 8
		Send Eighty{space}
	If Tens = 9
		Send Ninety{space}
}
return


d_Tens:
{	
	If Tens = 0
		Return
	If Tens = 1
		Gosub t_Teens
	If Tens = 2
		Send Twenty-
	If Tens = 3
		Send Thirty-
	If Tens = 4
		Send Forty-
	If Tens = 5
		Send Fifty-
	If Tens = 6
		Send Sixty-
	If Tens = 7
		Send Seventy-
	If Tens = 8
		Send Eighty-
	If Tens = 9
		Send Ninety-
}
return


t_Teens:
{	
	If Ones = 0
		Send Ten{space}
	If Ones = 1
		Send Eleven{space}
	If Ones = 2
		Send Twelve{space}
	If Ones = 3
		Send Thirteen{space}
	If Ones = 4
		Send Fourteen{space}
	If Ones = 5
		Send Fifteen{space}
	If Ones = 6
		Send Sixteen{space}
	If Ones = 7
		Send Seventeen{space}
	If Ones = 8
		Send Eighteen{space}
	If Ones = 9
		Send Nineteen{space}
}
return



t_Ones:
{	
	If Tens = 1
		Return
	If Ones = 0
		return
	If Ones = 1
		Send One{space}
	If Ones = 2
		Send Two{space}
	If Ones = 3
		Send Three{space}
	If Ones = 4
		Send Four{space}
	If Ones = 5
		Send Five{space}
	If Ones = 6
		Send Six{space}
	If Ones = 7
		Send Seven{space}
	If Ones = 8
		Send Eight{space}
	If Ones = 9
		Send Nine{space}
}
return

#x::ExitApp

If I'm asking a question about AHK, it's only because I can't find the answer anywhere else. I swear, I looked!

AutoHotKey has saved me at least 8 hours a month of data entry. What has it done for you?

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
A classical computer class assignment...
I thought of doing this for French in AutoHotkey, but the rules are much harder to apply...
Try an online tool if you are curious. (It is a Perl program.) Try 4227789 and see the difference between 200 and 201...
If you read French, you can have complete rules and a PHP program.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")