shahromi
25th June 2014, 12:17
Hi all,

I'm using CMG standard program script to print cheque. Customize the layout & report script to suit our requirement. However for text.wrapping function, the amount description is not displayed correctly:

Example:
199133.25
Result:
ONE HUNDRED NINETY NINE THOUSAND ONE THREE
HUNDRED THIRTY AND TWENTY FIVE CENTS ONLY

The amount description should be:
ONE HUNDRED NINETY NINE THOUSAND ONE HUNDRED
THIRTY THREE HUNDRED AND TWENTY FIVE CENTS ONLY

Using this function:
function text.wrapping()
{

domain tcmcs.st150m Desc
long Len_Desc ,i,LenT_Str
amount.desc1 = " "
amount.desc2 = " "
|amount.desc3 = " "

Desc = toupper$(amount.desc)
Len_Desc = Len(Desc ) | --- 68 chars

for i=1 to Len_Desc
pos_space = pos(Desc , " ") |--- 10 space

if pos_space > 1 then

LenTemp = len(Desc ) - (pos_space - 1) |100-9
Len1 = len(Desc ) - LenTemp
T_Str = Desc (1 ; Len1)
Desc = Desc (pos_space + 1 ; Len_Desc - pos_space)
LenT_Str = Len(T_Str)

Else
T_Str = Desc
LenT_Str = Len(T_str)

endif

If (Len(amount.desc1)+LenT_Str+5) < 45 then
if amount.desc1 <> "" then
amount.desc1 = amount.desc1 & " " & T_str
else
amount.desc1 = amount.desc1 & T_str
endif

Else
if amount.desc2 <> "" then
amount.desc2 = amount.desc2 & " " & T_str
else
amount.desc2 = amount.desc2 & T_str
endif

Endif

i = i + LenT_Str

endfor


}

Anybody can help me.
Thank you very much.

bhushanchanda
25th June 2014, 12:30
Hi,

What is your original amount description?

Note:- The thread is moved to correct forum. All coding related queries should be placed in this forum.

shahromi
26th June 2014, 03:21
Hi,

Original amount description(variable is amount.desc :
amount.desc =
ONE HUNDRED NINETY NINE THOUSAND ONE HUNDRED THIRTY THREE HUNDRED AND TWENTY FIVE CENTS ONLY

I want to display as
ONE HUNDRED NINETY NINE THOUSAND ONE HUNDRED
THIRTY THREE HUNDRED AND TWENTY FIVE CENTS ONLY

FYI: We have 2 lines to display amount desc. Max chars for first line = 45.

Thank You.

bhushanchanda
26th June 2014, 12:42
Hi,

You have 2 problems in your code.

1. I can see you leave some spaces before the first and second line. So, when your code checks the line:-

(Len(amount.desc1)+LenT_Str+5) < 45 it fails as length will cross 45 at this point:- ONE HUNDRED NINETY NINE THOUSAND ONE

Hence, just make it this:-

(Len(amount.desc1)+LenT_Str-5) < 45 as we are adding spaces from back so reduce it from the length.

2. Second problem is, when your code is done by the first line, it will still enter this condition, so we need a variable that will let the program know that the first line is done and bypass the condition
If (Len(amount.desc1)+LenT_Str+5) < 45.

Hence, here is the code you can try:-

function text.wrapping()
{

domain tcmcs.st150m Desc ,T_Str
long Len_Desc ,i,LenT_Str,pos_space,Len1,LenTemp
amount.desc1 = " "
amount.desc2 = " "
domain tcbool first.line
|amount.desc3 = " "

Desc = toupper$(amount.desc)
Len_Desc = Len(Desc ) | --- 68 chars
first.line = TRUE

for i=1 to Len_Desc
pos_space = pos(Desc , " ") |--- 10 space

if pos_space > 1 then

LenTemp = len(Desc ) - (pos_space - 1) |100-9
Len1 = len(Desc ) - LenTemp
T_Str = Desc (1 ; Len1)
Desc = Desc (pos_space + 1 ; Len_Desc - pos_space)
LenT_Str = Len(T_Str)

Else
T_Str = Desc
LenT_Str = Len(T_str)

endif

If (Len(amount.desc1)+LenT_Str+5) < 45 and first.line then
if amount.desc1 <> "" then
amount.desc1 = amount.desc1 & " " & T_str
else
amount.desc1 = amount.desc1 & T_str
endif

Else
first.line = FALSE
if amount.desc2 <> "" then
amount.desc2 = amount.desc2 & " " & T_str
else
amount.desc2 = amount.desc2 & T_str
endif

Endif

i = i + LenT_Str

endfor


}

shahromi
27th June 2014, 03:53
Thank You Mr. Bhushan.
Problem resolved, Alhamdulillah.
May Allah bless you. Amin.