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.
Adding Serial number in Crystal ReportCreate new Formula Field by right clicking on Formula field tab from Field Explorer. Give a name 'SrNo' and click Ok. In this formula workshop for the Field 'SrNo' declare variable numbervar 'srno' and increment it (srno:= srno+1;) in a while loop 'WhilePrintingRecords' .
To learn Roman numerals, know that I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, and M = 1,000. If a symbol comes after another symbol, then you add it to the symbol before it. For example, VI = 6 since V = 5 and I = 1. If a symbol comes before another symbol, subtract it instead.
A symbol placed before one of greater value subtracts its value; e.g., IV = 4, XL = 40, and CD = 400.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With