Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

help finding a command in FoxPro !!!

0 views
Skip to first unread message

Ayman H.

unread,
Aug 24, 1996, 3:00:00 AM8/24/96
to

hi, can someone tell me please if there is any function in foxpro that will
convert a number to its written text like
?function(11) -> eleven.
please reply to this mail if U have any idea.

if there is no function, what is the easy way to build a function that will
do that. I still won't believe it if they didn't include that kind of
function in FoxPro Library.


Hyperion Systems

unread,
Aug 24, 1996, 3:00:00 AM8/24/96
to

In article <4vnjba$g...@gaia.ns.utk.edu>, Ayman H. <Aym...@utm.edu> wrote:
>hi, can someone tell me please if there is any function in foxpro that will
>convert a number to its written text like
>?function(11) -> eleven.

Fox has no function to do that, so I, like many of you I am sure, write my
own "brute force" approach. The function NTOS (Number to String) shown
here can handle and number from 1 to 999,999. I use all lower case, if
you want proper or upper, just use those functions.

SAMPLE CALL (use on checks for instance):

checkamt = NTOS(m.dollars)+" and "+ALLTRIM(STR(m.cents))+"/100 Dollars"

John Torrance
Hyperion Business Systems, Inc.


*-- Convert any number from 1 to 999999 to text
FUCNTION ntos
PARAMETER pn_number
PRIVATE ALL LIKE lc_*
PRIVATE a, b, i, n, t, o

IF BETWEEN( pn_number, 1, 999999 )

lc_value = STR( pn_number, 6 )

lc_t1 = 'one'
lc_t2 = 'two'
lc_t3 = 'three'
lc_t4 = 'four'
lc_t5 = 'five'
lc_t6 = 'six'
lc_t7 = 'seven'
lc_t8 = 'eight'
lc_t9 = 'nine'
lc_t10 = 'ten'
lc_t11 = 'eleven'
lc_t12 = 'twelve'
lc_t13 = 'thirteen'
lc_t14 = 'fourteen'
lc_t15 = 'fifteen'
lc_t16 = 'sixteen'
lc_t17 = 'seventeen'
lc_t18 = 'eighteen'
lc_t19 = 'nineteen'
lc_t20 = 'twenty'
lc_t30 = 'thirty'
lc_t40 = 'forty'
lc_t50 = 'fifty'
lc_t60 = 'sixty'
lc_t70 = 'seventy'
lc_t80 = 'eighty'
lc_t90 = 'ninety'

*-- Find ones/tens value
t = VAL( RIGHT( lc_value, 2 ) )
o = VAL( RIGHT( lc_value, 1 ) )

IF t <= 20
i = "lc_t" + ALLTRIM( STR( t ) )
lc_retval = &i
ELSE
t = t - o
a = "lc_t" + ALLTRIM( STR( t ) )
b = "lc_t" + ALLTRIM( STR( o ) )
lc_retval = &a + " " + &b
ENDIF

*-- Find hundreds
h = VAL( SUBSTR( lc_value, 4, 1 ) )
IF h > 0
h = "lc_t" + ALLTRIM( STR( h ) )
lc_retval = &h + " hundred " + lc_retval
ENDIF

*-- Now, do the same for the thousands
t = VAL( SUBSTR( lc_value, 2, 2 ) )
o = VAL( SUBSTR( lc_value, 3, 1 ) )

IF t <= 20
i = "lc_t" + ALLTRIM( STR( t ) )
lc_retval = &i + " thousand " + lc_retval
ELSE
t = t - o
a = "lc_t" + ALLTRIM( STR( t ) )
b = "lc_t" + ALLTRIM( STR( o ) )
lc_retval = &a + " " + &b + " thousand " + lc_retval
ENDIF

*-- Find hundred thousands
h = VAL( LEFT( lc_value, 1 ) )
IF h > 0
h = "lc_t" + ALLTRIM( STR( h ) )
lc_retval = &h + " hundred " + lc_retval
ENDIF

ELSE

lc_retval = "* Out of Range *"

ENDIF

RETURN lc_retval

Hyperion Systems

unread,
Aug 24, 1996, 3:00:00 AM8/24/96
to

OOPS! Posted the buggy copy... the copy below actually works :)

- John

*-- Convert any number from 0 to 999999 to text


PARAMETER pn_number
PRIVATE ALL LIKE lc_*
PRIVATE a, b, i, n, t, o

#DEFINE ones = 1
#DEFINE tens = 2
#DEFINE hundreds = 3
#DEFINE thousands = 4

lc_retval = ""

IF BETWEEN( pn_number, 0, 999999 )

IF t > 0


IF t <= 20
i = "lc_t" + ALLTRIM( STR( t ) )
lc_retval = &i + " thousand " + lc_retval
ELSE
t = t - o
a = "lc_t" + ALLTRIM( STR( t ) )
b = "lc_t" + ALLTRIM( STR( o ) )
lc_retval = &a + " " + &b + " thousand " + lc_retval
ENDIF

lc_add = ""
ELSE
lc_add = "thousand "
ENDIF

*-- Find hundreds thousands


h = VAL( LEFT( lc_value, 1 ) )
IF h > 0
h = "lc_t" + ALLTRIM( STR( h ) )

lc_retval = &h + " hundred " + lc_add + lc_retval

Hyperion Systems

unread,
Aug 24, 1996, 3:00:00 AM8/24/96
to

OK, THIS one really works... no bugs.... guaranteed or your money back...

*-- Convert any number from 0 to 999999 to text

FUNCTION ntos


PARAMETER pn_number
PRIVATE ALL LIKE lc_*
PRIVATE a, b, i, n, t, o

lc_retval = ""

IF BETWEEN( pn_number, 0, 999999 )

lc_value = STR( pn_number, 6 )

lc_t0 = ""

DRMUS

unread,
Aug 27, 1996, 3:00:00 AM8/27/96
to

In article <4vnuiv$e...@nova.dimensional.com>, hype...@dimensional.com
(Hyperion Systems) writes:

>OK, THIS one really works... no bugs.... guaranteed or your money back...
>
>

Alright! Thanks. I didn't see the one that didn't work, but I tried this
out and it seems to work fine. Of course, you never really get something
for nothing, so I did a little extra on your function, and am giving it
back. The following code, added to what you have, allows the passed
parameter to be a string instead of a number. It also allows for commas.

For example, ntos("213,407")=two hundred thirteen thousand four hundred
seven

I don't know if this is of use to you, but it seems worth while.

Just guessing, but is this designed to be used with a check writing
program?

BTW, I think the generic PROCEDURE stripout at the end is a pretty handy
all purpose function that will strip all occurrences of any imbedded
substring from any string. If I had written that sucker before I could
have saved myself a lot of lines of code.

Cheers,
Dan.
******************
* near the beginning of the program, insert:
IF TYPE("pn_number")="C"
DO stripout WITH pn_number, ","
pn_number=VAL(pn_number)
ENDIF
* at the end, add this PROCEDURE:
*************************************************
PROCEDURE stripout
PARAMETERS string, stripchar
DO WHILE stripchar$string

string=SUBSTR(string,1,AT(stripchar,string)-1)+SUBSTR(string,AT(stripchar,
string)+LEN(stripchar))
ENDDO
*************************************************

Keith Trangmar

unread,
Sep 6, 1996, 3:00:00 AM9/6/96
to

Dan

Check out the STRTRAN() function in your manual ...

Keith

0 new messages