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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Position of character in Memo field 2

Status
Not open for further replies.

Cozmo2

Technical User
Apr 7, 2006
87
0
0
US
I have Crystal 9.2. I have to take the number found in a memo field and write it out (24.5 would be "twenty four and one half hours"). I thought if I could locate the decimal I could print the numbers on either side. Any help would be appreciated.
 
I think you should isolate the numbers first and then use the towords function:

stringvar array x := split({table.memo}," ");
numbervar i;
numbervar j := ubound(x);
stringvar y := "";
for i := 1 to j do(
if not isnumeric(x) then
y := y + x+" " else
if isnumeric(x then
y := y + towords(tonumber(x),1)+" "
);
y

...where the 1 in the towords function indicates the number of decimals--although the decimals are expressed as a fraction like this: .5 becomes 5/10 or 50/100 if you set it to "2".

-LB
 
LB beat me to it but here is something similar.

You should also be aware that arrays will only hold up to 1000 values so if your memo field contains more than a thousand words and your number is in position 1001 then this method won't work

WhilePrintingRecords;
Local StringVar Text := {@test};
Local Numbervar i;
Local NumberVar tmpNumber;
Local StringVar strWhole;
Local StringVar strDecimal;

For i := 1 to ubound(Split(Text))
Do(
If IsNumeric(Split(Text)) Then
tmpNumber := ToNumber(Split(Text)));

strWhole := ToWords(Truncate(tmpNumber),0);

tmpNumber := tmpNumber - Truncate(tmpNumber);

If tmpNumber = 0.25 Then
strDecimal := 'and one quarter hour'
Else If tmpNumber = 0.5 Then
strDecimal := 'and one half hour'
Else If tmpNumber = 0.75 Then
strDecimal := 'and three quarter hours';
//add the rest of you rules here for other decimal values

If tmpNumber <> 0 Then
strWhole & strDecimal

Gary Parker
MIS Data Analyst
Manchester, England
 
lbass & GJParker,
Both of these solutions work! Thanks so much for you help and quick response!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top