To add the custom function to a Crystal report

This procedure works only with a project that has been created from Project Setup. Project Setup contains specific namespace references and code configuration that is required for this procedure, and you will be unable to complete the procedure without that configuration. Therefore, before you begin this procedure, you must first follow the steps in Project Setup.

In this section, you create a Crystal report that accesses your custom function.

  1. In Solution Explorer, right-click the project name in bold type, point to Add, and then click Add New Item.

  2. In the Add New Item dialog box, in the Templates view, select the template named Crystal Report.

  3. In the Name field, enter the name FunctionTest.rpt, and then click Add.

    If you have not registered before, you are asked to register. To learn how to register, see Crystal Reports Product Keycode and Registration Number.

  4. In the Create New Crystal Report Document panel of the Crystal Reports Gallery dialog box, select Using a Report Wizard.

  5. In the Choose an Expert panel, select Standard, and then click OK.

  6. In the Available Data Sources panel of the Standard Report Creation Wizard window, expand the Create New Connection folder.

  7. From the subfolder that opens, expand the ODBC (RDO) folder.

  8. In the ODBC (RDO) window, select the correct ODBC DSN entry for your version of Crystal Reports, as explained in ODBC DSN Entry for Xtreme Sample Database, and then click Finish.

The ODBC (RDO) folder expands and shows the Xtreme Sample Database.
  1. Expand the Tables node and select the Customer table.

  2. Double-click the Customer table to move the table into the Selected Tables panel, and then click Next.

  3. CTRL-click Customer Name, Last Year's Sales, and City.

  4. Click the > symbol to move these fields into the Fields to Display panel, then click Next.

  5. In the Available Fields panel, under Report Fields, select Customer.City, click the > symbol to move the field into the Group By panel, and then click Finish.

The FunctionTest report is created and loaded into the main window of Visual Studio.
  1. If the Field Explorer is not visible, on the Crystal Reports toolbar, click Toggle Field View.
> [!NOTE]
> <P>Another way to display the Field Explorer is to go to the Crystal Reports menu, and then click Field Explorer.</P>
  1. In the Field Explorer, right-click Formula Fields, and then click New...

  2. In the Formula Name dialog box, type the name MyFunctionFormula, and then click Use Editor.

The Formula Workshop window is displayed, showing four panels horizontally.
  1. In the third panel, expand Functions.

  2. Expand Additional Functions, and within it expand Visual Basic UFLs (u2lcomm.dll).

The function that you created is displayed: ConvertUSDollarsToCDN.
  1. Double-click ConvertUSDollarsToCDN.
The ConvertUSDollarsToCDN() function appears in the lower panel, where you can now create your formula.
  1. In the lower panel, place your cursor within the function brackets.

  2. In the second panel, expand Report Fields, and then double-click Customer.Last Year's Sales.

Customer.Last Year's Sales is entered as the parameter within the ConvertUSDollarsToCDN function.
  1. On the toolbar, click Check.
The formula is verified, with no errors found.
  1. Close the Formula Editor.

  2. From the Field Explorer, within the Formula Fields node, drag MyFunctionFormula to the right of the Last Year's Sales field in the Detail section of the report.

  3. Arrange the fields to fit correctly on the report.

  4. Click Main Report Preview.

    The report is displayed, with your custom function having calculated the value of the MyFunctionFormula field.

  5. Click Main Report to exit Preview mode.