Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 588
Sivajith Avatar asked Jun 14 '12 08:06

Sivajith


People also ask

How can I add serial number 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' .

How do you find Roman letters?

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.

What is Roman letter XL?

A symbol placed before one of greater value subtracts its value; e.g., IV = 4, XL = 40, and CD = 400.


2 Answers

Just use the Roman() function provided by Crystal Reports

like image 68
soyeb Avatar answered Nov 15 '22 22:11

soyeb


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.

like image 44
LittleBobbyTables - Au Revoir Avatar answered Nov 15 '22 22:11

LittleBobbyTables - Au Revoir