To get a better understanding of how embedded custom code is used in a report, report developers can assume all of the code placed in the code window gets compiled into a make-believe class called Code . You can add properties and methods to the make-believe Code class, and call class members from expressions in the report, which has the class defined. Embedded code is compiled into a report's intermediate format and gets executed as needed when the report is rendered. Report Designer provides a simple text area to allow editing of the embedded code. To access the code editor, complete the following steps:
You should see a window similar to Figure 22.1 and can type the code in the Custom code area. Figure 22.1. Code editor
The code editor is basically a multiline text box, and it does not provide any productivity assistance, such as Intellisense or debugging. You have to be extremely careful while using this code editor. For example, only one level of "undo" action is allowed, as compared to Visual Studio's infinite undo. For all of its difficulties, embedded code provides several key benefits for a developer, including the following:
Every developer knows function reuse is beneficial over copy-and-paste programming. Take the following fictitious example. Suppose two developers were assigned the parallel development of a single report. One developer used embedded code, whereas the other one used simple expressions. One of the initial goals was to highlight negative values in red. Later, this goal changed to a more complex requirement, such as color -coding numeric ranges. The developer who used embedded code could adapt to the change in requirements quickly, and would make his manager happy, probably getting a bonus in the process. Embedded functions must be written in VB.NET. If you prefer C#, you would have to develop a custom assembly. This topic is covered in Chapter 23, "How to Create and Call a Custom Assembly from a Report." The following steps add the function used in the preceding narrative:
|