Using Variables and Formulae - Joining Strings and Non-Strings
When joining several pieces of information together, each piece of information must be a string. If you want to join a standard text and a field or variable that is not a string, you must convert the field or variable 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)
In this example, an integer is converted to a string and then added to a standard text:
- 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 and 23 if it is an integer. 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 HansaWorld Enterprise to crash when you print the report.
- the thousands separator that you want to be used in the string. In both examples, 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 page, which contains the Invoice Total for the whole report:
Dates
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 to appear in the vsDateText variable in Day, Month, Year order, 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.
Times
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 click the links below for more details about: