{"id":935,"date":"2008-07-08T00:36:23","date_gmt":"2008-07-08T07:36:23","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/books\/?p=935"},"modified":"2008-07-08T00:36:23","modified_gmt":"2008-07-08T07:36:23","slug":"2017-modifying-formulas","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/2017-modifying-formulas\/","title":{"rendered":"20.17 Modifying Formulas"},"content":{"rendered":"<h2>Modifying Formulas<\/h2>\n<p>The concepts that apply to modifying parameters are the same concepts for modifying formulas. RAS uses a similar object model for making changes to a formula. Rather than use the ParameterFieldController class, you use the FormulaFieldController. Listing 20-15 is the complete code listing.<\/p>\n<p>         <b>Listing 20-15. Modifying the value of a formula.<\/b><br \/>\n         <b>[VB.NET]<\/b><br \/>\n         <code>Public Shared Sub SetFormula(ByVal FormulaName As String, ByVal FormulaText As String, _<\/code><br \/>\n         <code>ByVal rcd As CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument)<\/code><br \/>\n         <code>Dim OldFormula As CrystalDecisions.ReportAppServer.DataDefModel.FormulaField, _<\/code><br \/>\n         <code>NewFormula As CrystalDecisions.ReportAppServer.DataDefModel.FormulaField<\/code><br \/>\n         <code>'Get a reference to the existing formula<\/code><br \/>\n         <code>Dim FormulaIndex As Integer<\/code><br \/>\n         <code>FormulaIndex = rcd.DataDefinition.FormulaFields.Find(FormulaName, _<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, _<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault)<\/code><br \/>\n         <code>OldFormula = DirectCast(rcd.DataDefinition.FormulaFields(FormulaIndex),  _<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.DataDefModel.FormulaField)<\/code><br \/>\n         <code>'Create the new formula and copy the old formula into it<\/code><br \/>\n         <code>NewFormula = New CrystalDecisions.ReportAppServer.DataDefModel.FormulaField()<\/code><br \/>\n         <code>OldFormula.CopyTo(NewFormula, True)<\/code><br \/>\n         <code>'Set the new formula text<\/code><br \/>\n         <code>NewFormula.Text = FormulaText<\/code><br \/>\n         <code>rcd.DataDefController.FormulaFieldController.Modify(OldFormula, NewFormula)<\/code><br \/>\n         <code>End Sub<\/code><br \/>\n         <b>[C#]<\/b><br \/>\n         <code>public static void SetFormula(string FormulaName, string FormulaText,<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rcd)<\/code><br \/>\n         <code>{<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.DataDefModel.FormulaField OldFormula, NewFormula;<\/code><br \/>\n         <code>\/\/Get a reference to the existing formula<\/code><br \/>\n         <code>int FormulaIndex;<\/code><br \/>\n         <code>FormulaIndex = rcd.DataDefinition.FormulaFields.Find(FormulaName,<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName,<\/code><br \/>\n         <code>CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);<\/code><br \/>\n         <code>OldFormula = (CrystalDecisions.ReportAppServer.DataDefModel.FormulaField)rcd.DataDefinition.FormulaFields[FormulaIndex];<\/code><br \/>\n         <code>\/\/Create the new formula and copy the old formula into it<\/code><br \/>\n         <code>NewFormula = new CrystalDecisions.ReportAppServer.DataDefModel.FormulaField();<\/code><br \/>\n         <code>OldFormula.CopyTo(NewFormula, true);<\/code><br \/>\n         <code>\/\/Set the new formula text<\/code><br \/>\n         <code>NewFormula.Text = FormulaText;<\/code><br \/>\n         <code>rcd.DataDefController.FormulaFieldController.Modify(OldFormula, NewFormula);<\/code><br \/>\n         <code>}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Modifying Formulas The concepts that apply to modifying parameters are the same concepts for modifying formulas. RAS uses a similar object model for making changes to a formula. Rather than use the ParameterFieldController class, you use the FormulaFieldController. Listing 20-15 is the complete code listing. Listing 20-15. Modifying the value of a formula. [VB.NET] Public [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47,40],"tags":[],"class_list":["post-935","post","type-post","status-publish","format-standard","hentry","category-chapter-20-dynamic-report-modification","category-crystal-reportsnet-2008","entry"],"_links":{"self":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/comments?post=935"}],"version-history":[{"count":0,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/935\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=935"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}