The following example shows how you can derive string fields by using a single expression script.
In this example:
There are two address fields in the database (displayed as address1 and address2 in the following image) that need to be concatenated (that is, joined together)
A comma and space are included in the concatenation to improve the readability. This can be achieved with one simple script expression.
For details about the Fields pane, see Appendix C, "Script Fields".
To create a new script
Click the New button on the Catalog of Available Fields dialog.
The Add Script Field dialog is then displayed.
Enter a name for your script in the Script Name text box.
In the example in the following image, the script has been named addresses.
To select the first field to concatenate
In the Fields list box, expand the Database Fields folder and double-click the required field, which is the first address field in the example.
The field is then displayed on the Script Code sheet, as shown in the following image.
To select the concatenation symbol
Expand the String operators in the Commands list box and then double-click the concatenation symbol (&), as shown in the following image.
If you know the symbol for concatenation, you can simply type it in rather than select it from the Commands list box.
At this stage, you could complete the expression simply by selecting the second address field. However, the address fields are to be separated by a comma and a space in this example.
To concatenate the comma separator
Type in the comma and a following space as a string; that is, between quotation marks, as shown in the following image.
To concatenate the second string
Select the concatenation symbol again (as described earlier in this section).
In the Fields list box, double-click the field that you want to concatenate.
In the example, this is the second address field; that is, address2.
The expression is now complete, as shown in the following image.
To complete the script, you need to set the return type. In this case, two address fields have been joined so it may also be necessary to extend the length of the result field to accommodate the combined strings.
To set the return type and change the length
Click the Define Return Type button in the top right corner of the Add Script Field dialog.
The Define Script Return Type dialog, shown in the following image, is then displayed.
Select the type from the Type list box. In this case, the String default return type is selected.
Enter a length in the Length text box. In this case, the length has been set to 60 to accommodate the combined address fields.
Click the Apply button to complete the definition.
The Define Script Return Type dialog is then closed and the return type is displayed in the Return Type list box in the top right of the Add Script Field dialog.
For more details about return types, particularly for users who are new to scripting concepts, see "Return Types and Parameters", earlier in this appendix.
To complete the script
Click the Apply button on the Add Script Field dialog.
The new script is then listed on the Script sheet of the Catalog of Available Fields dialog.
To include it in your report design, drag it on to the layout, as shown in the following image.
The contents of the Commands list box, Fields list box, and the Methods list box of the Add Script Field or Update Script Field dialog are described in:
Appendix B, "Script Commands"
Appendix C, "Script Fields"
Chapter 1 of the