by avista » Tue Oct 09, 2007 12:25 pm
// Testing
#include "FiveWin.ch"
//------------------------------------------------------------------------//
function Main()
local oDlg
local oGet
local nGet := 0
DEFINE DIALOG oDlg TITLE "Number To Word"
@ 5, 5 SAY "Number:" OF oDlg PIXEL
@ 5, 50 GET oGet VAR nGet OF oDlg SIZE 35, 12 PIXEL PICTURE "999999999999"
@ 25, 5 BUTTON "&Word" OF oDlg SIZE 35,12 ACTION Convert(nGet) PIXEL
@ 25, 50 BUTTON "&End" OF oDlg SIZE 35,12 ACTION oDlg:End() PIXEL
ACTIVATE DIALOG oDlg CENTERED
return nil
//------------------------------------------------------------------------//
function Convert(nGet)
local cWords := ""
local nRest := 0
local nNum := 0
cDigits := { "one ", "two ", "three ", "four ", "five " ,;
"six ", "seven ", "eight ", "nine ", "ten " ,;
"eleven ", "twelve ", "thirteen ","fourteen ","fifteen " ,;
"sixteen ", "seventeen ","eighteen ","nineteen " ;
}
cTens := { "twenty ", "thirty ", "forty ", "fifty ","sixty " ,;
"seventy ", "eighty ", "ninety " ;
}
nRest := nGet
IF nRest > 999999999
nNum := INT(nRest/1000000000)
nRest := nRest - INT(nRest/1000000000)*1000000000
cWords := cWords + Text(nNum) + "billion "
ENDIF
IF nRest > 999999
nNum := INT(nRest/1000000)
nRest := nRest - INT(nRest/1000000)*1000000
cWords := cWords + Text(nNum) + "million "
ENDIF
IF nRest > 999
nNum := INT(nRest/1000)
nRest := nRest - INT(nRest/1000)*1000
cWords := cWords + Text(nNum) + "thousand "
ENDIF
IF nRest > 0
nNum := nRest
cWords := cWords + Text(nNum)
ENDIF
msginfo(cWords)
return nil
//------------------------------------------------------------------------//
function Text(nNum)
local cText := ""
IF nNum > 99
cText := cText + cDigits[INT(nNum/100)] + "hundred "
ENDIF
nRest := nNum - INT(nNum/100)*100
IF nRest > 0
IF nRest < 20
cText := cText + cDigits[nRest]
ELSE
cText := cText + cTens[INT(nRest/10)-1]
IF nRest - INT(nRest/10)*10 > 0
cText := cText + cDigits[nRest-INT(nRest/10)*10]
ENDIF
ENDIF
ENDIF
return cText