cancel
Showing results for 
Search instead for 
Did you mean: 

passing formula values to Crystal Reports from c#

Former Member
0 Kudos

in an old vb 6 application we used to be able to call a function called PESetFomula in the Crystal Reports viewer and pass it the name of the parameter and the value.

How do we do that now using Crystal Reports for VS 2013. I don't mean to set the criteria just to pass over parameters and values.

Bill

Accepted Solutions (1)

Accepted Solutions (1)

former_member188030
Active Contributor
0 Kudos

Hi Bill,

Moving the thread to Crystal reports for Visual Studio Space.

Using the .net SDK you could use the ReportDocument class to pass the parameter values to the report.

See the sample applications here:

http://scn.sap.com/docs/DOC-6929

http://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports+for+.NET+SDK+Samples

The developer guide and the API reference guide is here.

http://scn.sap.com/docs/DOC-7824

- Bhushan

Senior Engineer

SAP Active Global Support

Follow us on Twitter

Got Enhancement ideas? Try the SAP Idea Place

Getting started and moving ahead with Crystal Reports .NET applications.

Answers (1)

Answers (1)

0 Kudos

Hi Bill,

First, CRPE32 API set has been deprecated, meaning you can no longer use crpe32 as your report engine. It's replacement is the inProc Report Application Server ( RAS ).

But in your case I think you are looking to set parameter values. But if you want to add Formulae here's how to.

For Parameters, search, I've posted sample code on how to.

After looking and testing with the test app's Bhushan directed you to here's how to add formula's. :

CrystalDecisions.ReportAppServer.ObjectFactory.ObjectFactory objFactory = new CrystalDecisions.ReportAppServer.ObjectFactory.ObjectFactory();

CrystalDecisions.ReportAppServer.DataDefModel.FormulaField Formula = (CrystalDecisions.ReportAppServer.DataDefModel.FormulaField)objFactory.CreateObject("CrystalReports.FormulaField");

Formula.Type = CrystalDecisions.ReportAppServer.DataDefModel.CrFieldValueTypeEnum.crFieldValueTypeStringField;

Formula.Syntax = CrystalDecisions.ReportAppServer.DataDefModel.CrFormulaSyntaxEnum.crFormulaSyntaxCrystal;

Formula.Text = @"whilereadingrecords; ""A"""; // "hello Ludek = 1"; // resultField.Text; // "n=3"; {Customer.Customer Credit ID} + 1 @"whilereadingrecords; ""A"""

Formula.Name = "TestDon"; // "TestDon"; //  resultField.Name; //"testformula";

String FormulaMessage = rptClientDoc.DataDefController.FormulaFieldController.Check(Formula);

if (FormulaMessage == null)

    rptClientDoc.DataDefController.FormulaFieldController.Add(Formula);

else

    btnReportObjects.Text += "There are errors in the formula: " + FormulaMessage.ToString() + "\n";

You must use the .Check to validate the formula, if not your reports may not work

Don