Crystal Reports - formula of full name to initial name - crystal-reports

How to display full name in short form like S.M.John in Crystal Reports.
Ex: Database value = Sammual Mbark John.
Need to display => S.M.John
Thank You

Considering your full name can have 2, 3, n names, I think this formula will do the job:
Stringvar result := "";
Local Numbervar i;
Stringvar Array output:= Split({Your.Field}, ' ');
for i := 1 to ubound(output) do (
if i <> ubound(output) then
result := result + left(output[i], 1) + "."
else
result := result + output[i]
);
result
Example and results:
1) "This Is My Test Name" will be "T.I.M.T.Name"
2) "Kurt Donald Cobain" will be "K.D.Cobain"
3) "Barack Hussein Obama" will be "B.H.Obama"
4) "Sammual Mbark John" will be "S.M.John"

Related

Convert Amount to Words in Crystal Report

I am working on a crystal report, can someone guide me how i can convert currency to words in this format;
(1,502,000.50) One million five hundred and two thousand naira and fifty kobo Only. i have tried:
numberVar x := {#summAmt} - int ({#summAmt});
if x = 0 then
propercase (toWords (int({#summAmt}),0)+ ' Naira Only')
else
propercase (toWords (int({#summAmt}),0)+ ' Naira, and ' + toWords ((x * 100),0) + ' Kobo')
To go around this, you will need 2 formulas; create the one i posted earlier, then create then create another formula with the following code:
numberVar x := {#summAmt} - int ({#summAmt});
if x > 0 then
replace ({#convertWords},"Hundred ","Hundred and " )
else
{#convertWords}
{#convertWords} is the name of my first formula and #summAmt is the name of the field i am converting.

Crystal Reports 2016 Sum field on two groups

I have a report that sums data and I am trying to modify it. I am trying to break out the totals by week by machine instead of one grand total by machine. Example of the calculations look like the following:
numberVar x := Sum ({WorkCntrSummary.Downtime_DurationInMinutes_Category0}, {WorkCntrSummary.Criteria_MachineID});
numberVar xh := Truncate(Round(x)/60);
numberVar xm := Round(x) mod 60;
if xh >= 1 then
ToText (xh, 0) + "h " + ToText (xm, 0) + "m"
else
ToText (xm, 0) + "m"
I am trying to change the 1st line where it is summing the field by MachineID. I want to sum it on the MachineID and also on a different group I added to the report which is a date field grouped by week. I am at a loss as to how to change that sum to add the date field by week to it. I tried changing it to the following, which doesn't do anything with grouping by week.
numberVar x := Sum ({WorkCntrSummary.Downtime_DurationInMinutes_Category0}, {WorkCntrSummary.Criteria_MachineID},{WorkCntrSummary.Criteria_StartDateTime});
numberVar xh := Truncate(Round(x)/60);
numberVar xm := Round(x) mod 60;
if xh >= 1 then
ToText (xh, 0) + "h " + ToText (xm, 0) + "m"
else
ToText (xm, 0) + "m"
But I get an error group condition must be a string.
Any help would be much appreciated.
Thanks!
Change
Sum ({WorkCntrSummary.Downtime_DurationInMinutes_Category0}, {WorkCntrSummary.Criteria_MachineID},{WorkCntrSummary.Criteria_StartDateTime})
to
Sum ({WorkCntrSummary.Downtime_DurationInMinutes_Category0}, {WorkCntrSummary.Criteria_StartDateTime})
In Crystal, the 2nd argument is what you group on. No need to chain all the grouping elements.

Display Serial Number as Roman letters in Crystal Reports

need to display serial no as roman letters(i,ii,iii,iv etc) in my crystal reports. I have the serial number captured as record number (1,2,3,4...).so what i have to do for it in crystal report.
Just use the Roman() function provided by Crystal Reports
I can't take much of the credit; I simply ported the code from this VB Helper article into Crystal, but it was a fun exercise:
NumberVar iCounter := 0;
Local StringVar ch := "";
Local NumberVar result := 0;
Local NumberVar new_value := 0;
Local NumberVar old_value := 0;
Local StringVar temp := "";
temp := UpperCase({?#Roman});
old_value = 1000;
For iCounter := 1 To Len(temp) do
(
// See what the next character is worth.
ch := Mid(temp, iCounter, 1);
if ch = "I" then new_value := 1
else if ch = "V" then new_value := 5
else if ch = "X" then new_value := 10
else if ch = "L" then new_value := 50
else if ch = "C" then new_value := 100
else if ch = "D" then new_value := 500
else if ch = "M" then new_value := 1000;
// See if this character is bigger
// than the previous one.
If new_value > old_value Then
// The new value > the previous one.
// Add this value to the result
// and subtract the previous one twice.
result := result + new_value - 2 * old_value
Else
// The new value <= the previous one.
// Add it to the result.
result := result + new_value;
old_value := new_value;
);
// Format the number without commas or decimals
ToText(result, 0, "");
Simply replace my {?#Roman} parameter placeholder with your variable, and you're all set.
I tried to fix it [enter image description here][1]
<https://www.tek-tips.com/viewthread.cfm?qid=887691>
or
<https://www.tek-tips.com/viewthread.cfm?qid=1613334>
and
<https://www.youtube.com/watch?v=X_UaulmICtM&list=TLPQMTUwMjIwMjMRAYZJzCsXDQ&index=6>
specifically: at crystal report
TH1: Fomula fields/new/"nameabc"/enter/"Roman(GroupNumber)"/ ctrl+S/and pull it out
TH2: Fomula fields/new/"nameabc"/enter/
select GroupNumber
case 1 : " I"
case 2 : " II"
case 3 : " III"
case 4 : " IV"
case 5 : " V"
case 6 : " VI"
case 7 : " VII"
case 8 : "VIII"
case 9 : " IX"
case 10 : " X"
case 11 : " XI"
case 12 : " XII"
case 13 : "XIII"
case 14 : " XIV"
case 15 : " XV"
case 16 : " XVI"
case 17 : "XVII"
default : ""
/ ctrl+S/and pull it out
But it really doesn't help t so there will be this 3 case (t improved from link 2-3) it can apply to the 3rd or even 10th group of headings
TH3: ex: (you want to create a text message for group 3)
Formula fields/new/"nameabc"/enter/
"
WHILEPRINTINGRECORDS;
GLOBAL NUMBERVAR INTSTTGRTEST;
INTSTTGRTEST :=0;
/ ctrl+S/ drag it out and put it in heading group 2 and hide it (= right click/format field/common/ check Suppress/ok) you can go to link 3 to see
Formula fields/new/"nameabcd"/enter/
"
WHILEPRINTINGRECORDS;
GLOBAL numbervar INTSTTGRTEST := INTSTTGRTEST + 1;
stringvar y;
STRINGVAR ARRAY X := ["A","B","C","D","E","F","G","H","I","J","K", "L","M","N","O","P","Q","R","S","T","U","V","W","X ","Y","Z"];
if INTSTTGRTEST <= 26 then (
redim preserve X[INTSTTGRTEST];
y := X[INTSTTGRTEST]
);
y;
/ ctrl+S/and pull it out and place it at group 3
and the alphabet can be whatever we want. ex:
X := ["I","II","III","IV","V","VI","VII","VIII","IX","X","XI" ,"XII","XIII","XIV","XV","XVI","XVII","XVIII","XIX","XX","XXI","XXII","XXIII"," XXIV","XXV","XXVI","XXVII","XXVIII","XXIX","XXX","XXXI","XXXII","XXXIII","XXXIV","XXXV","XXXVI" ,"XXXVII","XXXVIII","XXXIX","XL","XLI","XLII","XLIII","XLIV","XLV","XLVI","XLVII","XLVIII"," XLIX","L"];
or
X := ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
hope it can help you
enter code here [1]: https://i.stack.imgur.com/OeBBQ.png

'The string is non-numeric' error in a crystal reports Formula

I have put a formula to display the value of a field after masking it in crystal reports. but it shows me an error 'The string is non-numeric' in cardno variable. Following is code of my formula:
StringVar cardno;
NumberVar current_len;
NumberVar card_len;
NumberVar start;
NumberVar last;
StringVar ca;
card_len := ToNumber (Mid ({#lens},1,2));
start := ToNumber (Mid ({#lens},3,2));
last := ToNumber (Mid ({#lens},5,2));
current_len := Length (Trim (ToText({CA.CA}, 0 ,'')));
ca := ReplicateString("0",card_len-current_len) + Totext({CA.CA},0,'');
If card_len > current_len Then
If start = 0 Then
If last <= 1 Then
cardno := Mid(ca, last, card_len)
Else
cardno := ReplicateString("X",last-start-1) + Mid(ca, last, card_len)
Else
cardno := Mid (ca,1,start) + ReplicateString("X",last-start-1) + Mid(ca, last, card_len);
Please provide a solution to avoid this error. Thanks in advance.
Why don't you do something like this:
Select Len({table.field})
//AmEx
Case 15: Picture({table.field}, "XXXX XXXXXX XXXXX")
//Visa
Case 16: Picture({table.field}, "XXXX XXXX XXXX XXXX")
Default: {table.field}
** edit **
Replace(Space(Len({table.field})-4), " ", "X") + Right({table.field},4)

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)