Format or manipulate data in Reports or DataWindows

To print bar codes which contain exactly the data you require, you may need to format or manipulate your data, before your data is printed as bar codes.

In Reports or DataWindows, Column objects are usually used to display or print fields. The Format property of Column objects allows you to print the field using a simple format.

If you cannot achieve the results you want using the Format property of the Column object, then you must use a Computed Field object instead. The Expression property of a Computed Field object can call PowerBuilder functions to produce any result you need.

It is a good idea to use a Computed Field to display or print data in the format you need, or to manipulate data to achieve the results you want, before you print that result as a bar code.

You can also use a Computed Field to print values which are calculated using data from multiple fields.

The PowerBuilder String( ) function is a very powerful and flexible way to format values; text, number, date, etc. See the PowerBuilder Help files for a full description of the Sting( ) function.

Adding a Computed Field to a Report or DataWindow design

To add a Computed Field object to a Report or DataWindow you must be in design mode. To open your Report or DataWindow in design mode;

- If you are in Preview mode, select menu Design | Preview and uncheck Preview if it is checked.

To add a Computed Field object to your Report or DataWindow design;

- Select menu Objects | Computed Field

- Click in the Report or DataWindow in the position you want the new field to be created.

- In the Computed Object dialog box you can enter a Name for the object and the PowerBuilder Expression to calculate each time the field is displayed or printed.

Computed Field dialog box

Name

In the Name box you should enter a unique name for the new Computed Field object. The name should not be the name of any; field, object or reserved word.

Note: The Name can be used to reference the value of the Computed Field object, in other objects, or in PowerBuilder scripts.
Expression

The Expression property can be set to a simple expression. For example, the expression to display or print the value of the client_number field is;

client_name

The Expression property can also include PowerBuilder functions and it can be as simple or as complicated as you need.

The sections below provide useful additional information, about how to use expressions in Computed Fields, to format or manipulate data (i.e. numbers, strings, dates).

When you have an expression which displays or prints the data you require, you can then use that expression to print the data as a bar code;

See: Printing bar codes in PowerBuilder.

Dates

To format dates correctly as; 2 digit year, 2 digit month, 2digit day;

String ( date, "yymmdd" )

or 4 digit year;

String ( date, "yyyymmdd" )

If the date was 07/04/01, the result would be 20010704. 

Because the date is now formatted using only digits, a numeric only bar code types to be used (e.g. Interleaved 2 of 5).

If you need to print a 'Use By' date, which is 30 days after the date in the production_date field, use the RelativeDate( ) function;

String ( RelativeDate (production_date, 30), "yyyymmdd" )

Concatenating (adding) text fields

If you wish to print two fields in the same bar code;

field1 + field2

you may wish to use a character (e.g. comma) to delimited the fields;

field1 + "," + field2

Using this example data;

... STATE CLIENT ...
  MN 526  

If you use this expression in the Computed Field;

state + client

the result displayed by the Computed Field is;

MN526

Zero padding numbers

Tip: If we use leading zeros, to produce fixed length data, any resulting bar codes will be the same length.

Using this example data;

... ID ...
  1  
  523  
  98  

If you use this expression in the Computed Field;

String ( field, "0000" )

the results displayed by the Computed Field are;

0001
0523
0098

Special ASCII characters

The PowerBuilder function Char( ) can be used to return special non-printable ASCII characters. For example, ASCII character 14 is the Carriage Return character (ASCII symbol CR).

Using this example data;

... STATE CLIENT ...
  MN 526  

If you use this expression in the Computed Field;

state + Char(14) + client

If the result of this expression is used to print a bar code, when the bar code is read, two fields would automatically be filled, because the CR is interpreted as ENTER;

Note: In general, it is not always a good idea to put ASCII control codes in bar codes, just to make the bar codes work with your current software. Bar codes which contain ASCII control codes may not work with every hardware setup, or with future software.

Upper( ) function

The PowerBuilder function Upper( ) converts all text in a string in to uppercase. 

If you are printing Code 39 bar codes, any lowercase letters will result in a wider bar code. For example, consider these two values;

DATA-ABC
data-abc

The Code 39 bar code containing the lowercase text data-abc will be almost twice as wide as the bar code containing uppercase text DATA-ABC.

If you use this expression;

Upper ( client_code )

the width of all printed Code 39 bar codes will be reduced (useful if you need to use small labels).

Printing Code 39, using Upper( ), has another advantage, if all of your data values are the same length, then the bar codes will also be the same size.

The data in bar codes is usually used to locate records. In many applications it is not important if the data in the bar code is lowercase or UPPERCASE.


Copyright 2000 CIA (BAR CODES) UK. All rights reserved. Reproduction prohibited.