Related Information Examples & Tutorials

How To Format Text Fields And Text Variables

This topic discusses formatting text and shows you the symbols that are used to apply different formatting techniques to your printed output.

Overview

You may need to set the width of the field or trim trailing spaces from the end of the data. By default, when printing a database field, the printed length is the length of the field that is stored in the database, and NOT what is shown in Collect! on the form.

For example, the Client Name (@cl.na) is allotted 41 characters in Collect! However, 35 characters are displayed on the Client form. If the client's name is less than 41 characters wide, it will be filled with spaces. The next field or text will display at the end of these spaces. This can result in unexpected and undesirable positioning of data on your report.

You may want to control the width of fields, their justification, and other details. This can be very helpful when you are trying to align columns in a report.

You can even pull sub strings from a string of text, such as the Notes field in the Debtor form.

Top of page.

Text Formatting Codes

tip.gif The following formatting information applies to text variables as well as text fields.

The following codes, used AFTER the field code, define the field's format in the report or letter.








<Left Justify Field.
If a field is filled with spaces, the Left Justify option removes any trailing spaces from the field.

Example:
@cl.na< prints 'Joe Client'.
> Right Justify Field.
If a field is displayed within a certain width, the data can be right justified within the space allotted to the field.

Example:
@cl.na>prints '     Joe Client'.
<nn> Print nn characters wide (nn is a number).
This option forces a field to be printed within a specified width. If the field is too long, only the number of characters represented by (nn) will print. If the field is too short, it will be left justified and padded with spaces up to the specified width.

Examples:
@cl.na<8> prints 'Joe Clie'.
@cl.na<20> prints 'Joe Client        '.
>nn> Right justify and print nn characters wide (nn is a number).
This option forces a field to be printed within a specified width. If the field is too long, it will be truncated. If the field is too short, it will be right justified and padded with spaces up to the specified width.

Examples:
@cl.na>20> prints '        Joe Client'.
@cl.na>8> prints 'Joe Clie'.
<nn< Left justify and print nn characters wide (nn is a number).
This option forces a field to be printed within a specified width. If the field is too long, it will be truncated. If the field is too short, it will be left justified and padded with spaces up to the specified width.

Examples:
@cl.na<20< prints 'Joe Client        '.
@cl.na<8< prints 'Joe Clie'.
<n,n> Print n characters starting at position n (n,n are numbers).
This option will pull the specified number of characters from a string of text, starting after the character position specified by the second number in the code.

Examples:
@de.ss prints "123-45-6789" and
@de.ss<4,7> prints "6789" - the last 4 digits, starting after position 7.
<s> Strip everything except numerics from a string.
This might be used for dialing campaigns or electronic file submissions.

Examples:
@de.ho prints "123-453-6789" and
@de.ho<s> prints "1234536789"

Top of page.

Fixed Length In Reports

Using the format <nn> described above, it is possible to create fixed length in reports. This allows you to format your report to line up any way you want. Saved as a file, this report can then be imported into another program, such as a spreadsheet, database or word processor.

tip.gif When you export this report to a spreadsheet, you must setup in the spreadsheet program to make sure that it doesn't skip white space when loading the report file.

This example loops through transactions: @tr no total

searching for a posted date that the user enters when the report is run: where (@tr.pda = ?)

//Code sample for fixed length file

@tr no total where (@tr.pda = ?) where (@tr.ofcs = X)
@tr.pda<10> @tr.des<50> @tr.ty<3> @tr.tu<13> @tr.di<13> @tr.ca<13>
@tr

Putting the <nn> after each field tells Collect! to output that many characters regardless. We end up with a perfect fixed length file.

Top of page.

Formatting Phone Fields

If you are using the 'Numerics only in phone fields' switch in Screen and Messages, for auto dialing systems, there may be times when you want your phone fields formatted differently for reports. You can use the <n,n> formatting code to achieve this.

Example:

Company Details Phone number: 1234567890

In your report:

Phone: (@cd.ph<3,0>) @cd.ph<3,3>-@cd.ph<4,6> outputs
Phone: (123) 456-7890

This does not work with variables. You must format the actual field code, in this case, @cd.ph.

Top of page.

Parsing Names

You can separate first and last names and only print the first name in a report., or first name, middle name and initials.

Top of page.

Fn

To print only the first name, use this:

<fn>

SYNTAX: @de.na<fn>

@de.na will print SMITH, JAMES T. RYAN, for example.
Use @de.na<fn> to print JAMES

tip.gif When <fn> is used, the closing angle bracket must immediately follow the code.

Top of page.

Fns

To print first and middle names and initials, use this:

<fns>

SYNTAX: @de.na<fns>

@de.na will print SMITH, JAMES T. RYAN, for example.
Use @de.na<fns> to print JAMES T. RYAN

tip.gif When <fns> is used, the closing angle bracket must immediately follow the code.

Top of page.

Mns

To print only middle names and initials, use this:

<mns>

SYNTAX: @de.na<mns>

@de.na will print SMITH, JAMES T. RYAN, for example.
Use @de.na<mns> to print T. RYAN

tip.gif When <mns> is used, the closing angle bracket must immediately follow the code.

Top of page.

Ln

To print only the last name, use this--

<ln>

SYNTAX: @de.na<ln>

@de.na will print SMITH, JAMES, for example. Use @de.na<ln> to print SMITH

tip.gif When <ln> is used, the closing angle bracket must immediately follow the code.

Top of page.

Assigning Formatted Text To A Variable

You can also assign a formatted text field to a variable. This works for any printable information text field. Any of the text formatting operators may be used.

Example 1:

@varStr* = @de.ss<4,7>

If the SSN is 011-23-1234, then @varStr now holds 1234. This is 4 characters of the SSN, starting at position 7.

And you can apply formatting when assigning one variable to another.

Example 2:

@varStr2* = @varStr<010>

Now the value in @varStr2 is the value that was in @varStr plus now it is padded with zeroes up to 10 spaces.

tip.gif This is very useful when creating special reports for electronic processing where data must meet special formatting requirements.

Top of page.

Mask Report Field

You can use the report writer to mask characters when printing field data in a report. This is useful for security issues when you do not want to display personal account information.

SYNTAX: {field code}<M{n},{nn},{mask character}>

tip.gif Syntax is case sensitive.

n - Position to start masking. Position 0 is the first character.

nn - Number of characters to mask from start position. Entering a mask length larger then the field size will result in a mask up to the end of the data field.

mask character - character to use for masking, e.g. [*, #] - You cannot use % as a mask because Collect! uses this symbol for internal report writing functions.

EXAMPLE:

@de.ss<M2, 7, *>

This results in starting masking at the third character and masking up to seven characters in the debtor's SSN, as shown below.

If the Debtor SSN is 065-76-0138, the printed output would be

06*******38 The seven masked characters are 5-76-01. Masking counts all characters, including the hyphens.

tip.gif This feature also works with variables. and you can also assign a masked text field to a variable.

Example:

@varStr* = @de.ss<M2, 7, *>

Top of page.

Summary

Reports that ship with the demonstration database use these formatting techniques. Please view the Report Definitions list to find reports and letters.

Top of page.

See Also

- How To Format Numeric Fields And Numeric Variables
- How To Control Font Attributes
- How To Format Variables When Assigning
- Report Sample to view sample reports and letters
- Report Topics Index for a list of all report and letter topics

Top of page.

Was this page helpful? Do you have any comments on this document? Can we make it better? If so how may we improve this page.

Please click this link to send us your comments: helpinfo@collect.org