Language:


Using Variables and Formulae - Joining Two or More Pieces of Information Together

You can join several pieces of information together in a single variable. This is known as "concatenation". For example, in the Customer Footer section, it might improve the appearance of the report if we added the Customer Number or Name to the text "Total for Customer" that is already there. The various pieces of information that you join together must be strings. You can do this using one of two methods:
  1. Declare a string variable at the beginning of the report on the 'Data' card. Then, use the [Code] button to add a line of code that joins the various pieces of information together and places the result in the string variable. Turn to the 'Layout' card and use the [Formula] button to place the string variable in the appropriate section of the report.

  2. An alternative method is to bypass the 'Data' card altogether. Instead, use the [Formula] button to join the various pieces of information together and place the result in the appropriate section of the report. This method is faster to write and means that there are fewer variables in the report. However, by bypassing the 'Data' card you risk making the report definition harder to read and edit in future, because code is divided between the 'Data' and 'Layout' cards.
The example shown below illustrates the first method. A new string variable vsCustText has been declared at the beginning of the report and its contents are changed for every Customer:

The code that joins the standard text ("Total for Customer") and the Customer Number is placed in the Customer register section, so it will be used once for each Customer. Whatever was previously in the vsCustText variable will be lost. The code is:
code: vsCustText="Total for Customer "&vrCustomer.Code
The standard text including final space is placed in inverted commas "". The standard text and the Customer Number are joined using the ampersand &. You can place a space either side of the ampersand to make the code easier to read:
code: vsCustText="Total for Customer " & vrCustomer.Code
These spaces will be ignored when the report is printed.

Use the [Formula] button to place the variable in the Invoice Footer section on the 'Layout' card, in the same way as described on the Printing a Variable page:

If you don't want to use variables, simply click the [Formula] button on the 'Layout' card. When the 'Formula' dialogue box opens, type in the code that joins the various pieces of information together. For example, the vsCustText variable and its line of code could be replaced with this formula:

To join several pieces of information together, place an ampersand between each element. This example prints the word "Customer:" followed by the Customer Number and Name. A comma and space will be printed between the Number and the Name. The word "Customer:" and the comma and space are both fixed text and are therefore enclosed in inverted commas:
"Customer: " & vrCustomer.Code & ", " & vrCustomer.Name