cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Reports with Visual Studio Field Issues

Former Member
0 Kudos

I have an issue where I have created a report and I am using C# code to retrieve a value from a SQL server database and the way the value is displaying on the report is wrong.

The value from the database is "123456" but on the report it is showing up as "123,456.00"

I have tried to format this field every type of way but it always appears the same. It is currently a Formula Field because this number will be used in another Formula Field to generate a barcode.

I created another Formula Field and used

Replace(Replace(ToText({@TagID}),",",""),".","")

That replaced the comma and decimal point just fine, but the zeros remained, displaying the value as "12345600"...still wrong. I do not want a hack type of solution to remove trailing zeros, because some values put into that database might have zeros, such as "500" or "1000".

It seems like the system in which formatting objects in Crystal Reports inside Visual Studio is very limited. Please tell me there is a solution for this issue, it is so tedious!

Thank you for your time!

Accepted Solutions (1)

Accepted Solutions (1)

abhilash_kumar
Active Contributor
0 Kudos

Hi Michael,

Use:

ToText({@TagID},'#')


-Abhilash

former_member280812
Active Participant
0 Kudos

hi Michael,

Try to use:

ToText({@TagID},'0')

Former Member
0 Kudos

Thanks for the replies, everyone.

I tried using ToText({@TagID},'0') but when I check the formula for errors it says "Too many arguments have been given to this function"

former_member280812
Active Participant
0 Kudos

Hi Michael,

Make sure @TagID is not a type of string/text make sure that is an integer or decimal etc...

or

You can used the field directly on your formula like this ToText({yourField},'0')

Former Member
0 Kudos

The field is a formula field. I need to be able to do this on a formula field.

DellSC
Active Contributor
0 Kudos

Try ToText({@TagID}, 0, "").  The 0 tells it to not include any decimal and the double quotes at the end tell it to not use commas for the thousands separator.

Or, you can right-click on the field in your report, go to "Format Field", and set the number format there.

-Dell

former_member280812
Active Participant
0 Kudos

Hi Michael

May i see your code you used in the @TagID formula..

Thanks.

Former Member
0 Kudos

ToText({@TagID}, 0, "") results in 'Too many arguments have been given to this function'

I am assigning a value to the @TagID formula in my C# code:

theReport.DataDefinition.FormulaFields["TagID"].Text = "" +TheTag.ToString() + "";

'TheTag' being any integer, such as 123456 (showing up in the field as '123,456.00' and I HAVE tried formatting the field using the field properties available within Visual Studio but nothing I changed had any effect on this field...

DellSC
Active Contributor
0 Kudos

Since you're just setting the value of the formula in your app, I would recommend another way of doing this - use a parameter instead of formula.  Make the parameter a number and then format it in your report to remove the comma and decimals.

-Dell

0 Kudos

Another way is to get CR to check the formula before adding:

String FormulaMessage; // if not null that is the error message
try
{
    FormulaMessage = "\n" + rptClientDoc.DataDefController.FormulaFieldController.Check(resultField);
}
catch (Exception ex)
{
    btnReportObjects.Text += "\n" + ex.Message + "\n";
    FormulaMessage = "";
    btnCount.Text = flcnt.ToString();
    break;
}
textBox1 = "";

if (FormulaMessage != null)
{
    btnReportObjects.Text += FormulaMessage.ToString() + "\n";
    if (FormulaMessage != "\n") // || FormulaMessage.Substring(0, 14) == "Error in formula") //\nError in formula  ~: \n'NumberVar DoBVar := IIF((100 * MONTH(currentdate) + DAY(currentdate)) < (100 * MONTH({Command.BirthDate}) + DAY({Command.BirthDate})), 1, 0);\r'\nThis field name is not known.\nDetails: errorKind"
    {
        FormulaMessage = @"This field name is not known";
        btnReportObjects.AppendText("\n");
        ++Errorcnt;
        btnErrorCount.Text = Errorcnt.ToString();

        //string myURL = @"http://search.sap.com/ui/scn#query=" + FormulaMessage + "&startindex=1&filter=scm_a_site%28scm_v_Site11%29&filter=scm_a_modDate%28*%29&timeScope=all";
        //string fixedString = myURL.Replace(" ", "%20");

        ////System.Diagnostics.Process.Start(@"C:\Program Files (x86)\Internet Explorer\iexplore.exe", myURL);
        //System.Diagnostics.Process.Start(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe", fixedString);

    }
}

Don

PS - if you want to catch errors or exceptions you can use the above code to open a browser and search SCN ( SAP public forums ) for the error... Or redirect it to your own Forums for support...

Answers (1)

Answers (1)

0 Kudos

Moved to .NET SDK forum