Convert Number to words in Crystal Report using Crystal Syntax - crystal-reports

I'm working on the task to convert the number to words using Crystal Report and Crystal syntax as well.
I did well for any amount <100K with the code below but face the problem with amount >100K (in VN currency, we even convert hunderds billions, not only 10K or millions). Could some one helps me to find the way to handle this issue to convert any amount to words .
Thank you in advance for any help from you.
//the array value is the wording of number in EN Zero, One, Two, Three...
local stringvar array Array_Items:= ["không","một","hai","ba","bốn","năm","sáu","bẩy","tám","chín"];
local numbervar x;
local numbervar z;
local stringvar strcuaso;
z:=10000;
local numbervar s10k;
local stringvar strs10k;
local numbervar s1k;
local stringvar strs1k;
local stringvar th;
local numbervar stram;
local stringvar strstram;
local numbervar schuc;
local stringvar strschuc;
local numbervar sdonvi;
local stringvar strsdonvi;
local stringvar a;
x:=50031;
strcuaso:=totext(x,2,"");
s10k:=tonumber(left(strcuaso,1));
s1k:=tonumber(mid(strcuaso,2,1));
if((s10k=1)and(s1k=0))then
strs10k:="mười";
if((s10k=1)and(s1k=0))then
strs1k:="nghìn";
if((s10k>1)and(s1k=0))then
strs10k:=totext(Array_Items[s10k+1])+" mươi ";
if((s10k>1)and(s1k=0))then
strs1k:="nghìn";
if((s10k=1)and(s1k>=1))then
strs10k:="mười ";
if((s10k=1)and(s1k>=1))then
strs1k:=totext(Array_Items[s1k+1])+" nghìn ";
if((s10k>1)and(s1k=1))then
strs10k:=totext(Array_Items[s10k+1])+ " mươi ";
if((s10k>1)and(s1k=1))then
strs1k:=" mốt nghìn ";
if(s10k>1)and(s1k>1)then
strs10k:=totext(Array_Items[s10k+1])+ " mươi ";
if(s10k>1)and(s1k>1)then
strs1k:=totext(Array_Items[s1k+1])+" nghìn ";
stram:=tonumber(mid(strcuaso,3,1));
schuc:=tonumber(mid(strcuaso,4,1));
sdonvi:=tonumber(mid(strcuaso,5,1));
strstram:=" "+totext(Array_Items[stram+1])+" trăm ";
if((schuc=0)AND(sdonvi=0))then
th:="A" ;
if((schuc=0)AND(sdonvi>=1))then
th:="B";
if((schuc=1)and(sdonvi>0))then
th:="C1";
if((schuc=1)and(sdonvi=0))then
th:="C2";
if((schuc>1)and(sdonvi=0))then
th:="D";
if((schuc>1)and(sdonvi=1))then
th:="E"; //strsdonvi="mốt";
if((schuc>1)and(sdonvi>1))then
strsdonvi:=totext(Array_Items[sdonvi+1])
th:="F";
if(th="A")then
strschuc:="";
if(th="A")then
strsdonvi:="";
if(th="B")then
strschuc:="";
if(th="B")then
strsdonvi:=" linh " +totext(Array_Items[sdonvi+1]);
if(th="C1")then
strschuc:="mười ";
if(th="C1")then
strsdonvi:=totext(Array_Items[sdonvi+1]);
if(th="C2")then
strschuc:="mười";
if(th="C2")then
strsdonvi:="";
if(th="D")then
strschuc:=totext(Array_Items[schuc+1])+" mươi " ;
if(th="D")then
strsdonvi:="";
if(th="E")then
strschuc:=totext(Array_Items[schuc+1])+" mươi " ;
if(th="E")then
strsdonvi:=" mốt ";
if(th="F")then
strschuc:=totext(Array_Items[schuc+1])+" mươi";
if(th="F")then
strsdonvi:=totext(Array_Items[sdonvi+1]);
if(x=z)then
a:="Mười nghìn VND"
else
a:=ProperCase(strs10k)+strs1k+strstram+strschuc+strsdonvi+" VND ";

Related

crystal report - if else statement when array is declared: string length error

I'm a noob in Crystal Report.
I'm getting String length is less than 0 or not an integer error.
on left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1)
of the code below:
local StringVar mDate;
local StringVar mMonth;
local StringVar mDay;
local StringVar mYear;
if {ORDERCHECKVIEW.LOTNUMBER} = 'N/A'
then 'N/A'
else
mDate:= left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1);
mMonth:= left(mDate,2);
mDay := Mid (mDate,4 ,2 );
mYear := totext(2010 + CDbl (right(mDate,InStr(StrReverse(left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1)),"-") -1 )),0,""); // transform 2017
cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay));
cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay));
Can anyone please explain what's wrong? I don't think my if-else statement is wrong..
FYI, I have previously asked a question and this question is a follow-up:
(Advanced conversion of a single number to year, along with hyphen)
compounded if-else
local StringVar mDate;
local StringVar mMonth;
local StringVar mDay;
local StringVar mYear;
if {ORDERCHECKVIEW.LOTNUMBER} = "N/A"
then "N/A"
else
(
mDate:= left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1);
mMonth:= left(mDate,2);
mDay := Mid (mDate,4 ,2 );
mYear := totext(2010 + CDbl (right(mDate,InStr(StrReverse(left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1)),"-") -1 )),0,""); // transform 2017
// cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay));
ToText(cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay)),"MM/dd/yyyy") ;
)

Show date after split it in Crystal Reports

How can I concatenate this a date in Crystal Reports after split it.
I have this formula:
global numberVar d :=toNumber(mid({BAQReportParameter.Option01},4,2));
global numberVar m:= toNumber(left({BAQReportParameter.Option01},2));
global numberVar y:= toNumber(right({BAQReportParameter.Option01},4));
Global stringVar datetxt;
datetext := ToText(d) + "/" + ToText(m) +"/" + ToText(y);
but it has an error.
global stringvar d :=(mid({BAQReportParameter.Option01},4,2));
global stringvar m:= (left({BAQReportParameter.Option01},2));
global stringvar y:= (right({BAQReportParameter.Option01},4));
Global stringVar datetxt:= ToText(d + "/" + m +"/" + y);
Do this simple changes it will work!!

Crystal Report Formula - Get numeric from alphanumeric characters

I need a way to extract a numeric value from an alphanumeric one, for example :
3 MS 15 SEC
Desired:
3.15
Try:
Local NumberVar i;
Local StringVar k;
for i:=1 to Count (Split("3 MS 15 SEC"," ")) do
(
if NumericText (Split("3 MS 15 SEC "," ")[i]) then (
k:=k+Split("3 MS 15 SEC "," ")[i]+".";
)
);
if k<>"" then
k[1 to length(k)-1]
else
k //drop final "."
Try:
// {#extract}
Local Stringvar Array tokens:=Split(x);
Local Stringvar Array values;
Local Numbervar i;
for i := 1 to uBound(tokens) do (
if isNumeric(tokens[i]) then (
redim preserve values[ubound(values)+1];
values[ubound(values)]:=tokens[i];
)
);
ToNumber( Join(values,".") );

crystal report: print missing records

i want to print missing records in crystal report .
i am using below formula in the report and i have placed this formula in details b section.
details a has normal report fields.
formula:
local numbervar firstemp; // first Emp#
local numbervar nextemp; // next Emp#
local numbervar diff; // difference between firstemp and nextemp
local numbervar increase; // increment for missing Emp#'s
local numbervar result;
increase := 0;
firstemp := tonumber({getRptSalesSummery;1.Bill_Id});
nextemp := tonumber(next({getRptSalesSummery;1.Bill_Id}));
nextemp := nextemp -1;
diff := nextemp - firstemp;
if nextemp = firstemp
then ""
else (
while diff >= 1
do (
diff := diff - 1;
increase := increase + 1;
result := firstemp + increase;
exit while;
);
totext (result,"0000") & chr(13);
)
this formula is not giving me range.
for example if in report there is range of 1 to 10 and 6,7,8,9 is missing records, then if i check in the report its printing 1 to 5 and 6 as missing then directly 10, but its not giving me 7,8,9.
basically i required range of missing records

crystal reports : character "." in domain string errors

My goal is the discern whether the domain has a subdomain or not by counting the number of periods there are in the domain name. If it has 2 periods, there is obviously a subdomain.
I have the following crystal reports formula written in crystal syntax
local numbervar count :=0;
Local numbervar strLen := length({?domain});
local stringvar c := {?domain};
local numbervar i;
local numbervar pos2 :=0;
for i:=1 to strLen do
( if Mid({?domain}, i, 1) = "." then
(
count := count + 1;
if count = 2 then (
pos2 := i
);
);
);
if count > 1 then
left({?domain}, pos2)
else
left({?domain},instr({?domain}, ".")-1)
any ideas? hopefully this is something my tired eyes are just glazing over.
UPDATE: here is the weird thing that happens.
If I add "+ totext(pos2)
if count > 1 then
left({?domain}, pos2) + totext(pos2)
else
left({?domain},instr({?domain}, ".")-1)
it outputs correctly subdomain.domain with the .com removed
if i run it without the totext(pos2)
if count > 1 then
left({?domain}, pos2)
else
left({?domain},instr({?domain}, ".")-1)
it only shows the subdomain part of subdomain.domain.com
Any ideas why?
Should there be a final ; on the last line?
Alternatively, have you considered making the entire formula something like:
Left({?domain},InStrRev({?domain}, ".")-1)