Creating a Report Generator Report - Using Variables and Formulae - Joining Strings and Non-Strings
This page describes bringing several pieces of information together into a single variable in a Report Generator report when at least one of those pieces of information is not a string (e.g. it is a number or a date). Please refer
here for more basic information about joining pieces of information together in a single variable.
---
When joining several pieces of information together in a single variable, each piece of information must be a string. If one of the pieces of information is not a string (e.g. it is a number or a date), you must convert it to a string. You can do this in the code or formula that joins the pieces of information together.
Decimals and Integers
Use the ValToString function to convert decimals and integers to strings. In this example, a decimal is converted to a string and then added to a standard text:
- vsInvText="Total: " & ValToString(vrInvoice.Sum1,2,",",".",0)
As well as decimals, you can convert integers to strings and then add them to standard texts:
- vsInvCount="No. of Invoices: "&ValToString(viInvCount,23,",",".",0)
The ValToString function takes five parameters (in the brackets separated by commas) as follows:
- the field, variable or number that you want to be converted to a string
- a number signifying whether the first parameter is a decimal or an integer. This number should be 2 if the first parameter is a decimal (first example above) and 23 if it is an integer (second example). If you enter the wrong number, the first parameter probably will not be converted to a string. If you leave this parameter empty, you may cause Standard ERP to crash when you print the report.
- the thousands separator that you want to be used in the string. In both examples above, the thousands separator is a comma. The thousands separator must be enclosed in quotation marks ("") because it is a string itself.
- the decimal point that you want to be used in the string. In both examples, the decimal point is a full stop. The decimal point must be enclosed in quotation marks ("") because it is a string itself.
- if the first parameter is a decimal, set the fifth parameter to 0 (zero) if you want the numbers after the decimal point to be included in the string. Set it to 1 if you do not want the numbers after the decimal point to be included in the string.
In the example formula shown below, the text "Total for the Report: " is joined to the vdInvTotal decimal variable described on the
Using Variables and Formulae - More Examples page. The vdInvTotal variable contains the Invoice Total for the whole report:
Use the DateToString function to convert dates to strings:
- vsDateText="Date: " & DateToString(vdDateVariable, "DD/MM/YYYY")
The DateToString function takes two parameters (in the brackets separated by a comma) as follows:
- the date field or variable that you want to be converted to a string
- a string specifying the date format that you to be used in the final string. In the example, we have specified that we want the date that is included in the vsDateText variable to use the Day, Month, Year format, and that two digits are to be used for the Day and Month (i.e. leading zeros are to be used) and four digits are to be used for the Year. This parameter must be enclosed in quotation marks ("") because it is a string itself.
Use the TimeToString function to convert times to strings:
- vsTimeText="Time: " & TimeToString(vtTimeVariable)
This function takes one parameter: specify in the brackets after the name of the function the time field or variable that you want to be converted to a string.
Longs
You can add long variables to strings without conversion:
- vsLongText=" Text: " & vlLongVariable
Please follow the links below for more details about:
---
Go back to: