811.txt
=====================================================================
Printing Bar Codes
=====================================================================
In version 4.0 of Crystal Reports for R:BASE, you can place bar codes
right on your reports. When you install Crystal Reports, you have the
option of installing bar code fonts. Fonts are installed for printing
two different types of bar codes: ZIP code bar codes, and Code 39 (3
of 9) bar codes. The fonts are copyrighted and licensed for use by
Azalea Software, Inc., P.O. Box 16745, Seattle, WA 98116-0745. In
addition to the fonts, Crystal Reports includes functions to convert
your data to the appropriate format for the bar code. Once installed,
the bar code fonts are also available to you in R:BASE, but R:BASE
does not have built-in functions to convert your data.
The Crystal Reports functions NumberToCode39, Number to Postnet,
StringToCode39, and StringToPostnet are listed under Additional
Functions in the Formula editor. The functions output numbers and
strings (respectively) in the format required by the Azalea bar
code fonts. In R:BASE you create your own expressions to convert data
to the proper format.
Code 39 Bar Codes
Code 39 or Code 3 of 9 is a bar code format used for ID, inventory,
and tracking purposes. This is the format of the bar code you see
printed on most products you purchase. The Code 39 font included with
Crystal Reports creates symbols that contain only the digits 0-9, not
the full Code 39 character set. A font supporting the full character
set, letters as well as numbers, is available from Azalea Software,
Inc.
In Crystal Reports, you can print a product number as a Code 39 bar
code by defining and locating a formula. The formula uses the
StringToCode39 for text data type fields or the NumberToCode39
function for integer fields to convert the field value to the required
format. For example:
NumberToCode39({products.prodid})
The formula is placed where you want the bar codes to print. Change
the font of the formula field to Code39Digits and set the font size.
For bar codes a half inch high, use 36 points, for example.
ZIP Code Bar Codes
POSTNET bar codes are the bar code symbols used to encode zip codes on
US mail. POSTNET symbols are different from other bar codes in that
the individual bar height varies rather than the bar width. Each
number is represented by a pattern of five bars. A single tall bar is
used for the start and stop bars.
The Crystal Reports function StringToPostnet converts a 5-digit zip
code to the appropriate format. Create and place the formula in the
appropriate location on the report or mailing label. Always format
the ZipCodeBarcode font at 16 points.
To convert a 10-digit zip code, the zip code value to be converted
can't have a dash separating the two parts of the zip code. Most zip
codes are stored in the database with the dash, because that is how
you want to print the actual zip code. Define the following formula
in Crystal Reports to remove the dash from the 10-digit zip code for
printing as a bar code. The formula correctly prints either a 5-digit
or a 10-digit zip code.
StringVar postal1;
StringVar postal2;
postal1:={employee.empzip}[1 to 5];
postal2:= {employee.empzip}[7 to 10];
If postal2 = " " Then
StringToPostnet (postal1)
else
StringToPostnet (postal1 +postal2)
Using ZIP Code Bar Codes in R:BASE
Data formatted for the zip code bar code font requires an "s" at the
beginning and end of the data as the start and stop character. A check
digit is also required. The check digit is the number added to the sum
of all the digits that results in a number divisible by 10. For
example, if the zip code is 98007, the sum of all the digits is
(9+8+0+0+7) or 24. The next highest number that is a multiple of 10
is 30, so the check digit is 6 (6 + 24 = 30). The check digit cannot
be calculated by a report expression or computed column.
Modify your table structure to include an integer data type column for
storing the check digit. Then, add an EEP to your form to calculate
the check digit as each data row is added or edited. The EEP is
placed on exit from the zip code field. Two form expression are
required:
vzip = empzip
places the zip code value from the column into a variable
for use by the EEP.
checkdigit = .vcheck
stores the calculated check digit value in the table.
The EEP calculates the check digit value based on the entered zip
code. The EEP calculates and stores the check digit when a new row is
added or when data is edited and the zip code value changes. The EEP
calculates the check digit for either a 5-digit or a 10-digit zip
code.
*(barcode.eep)
-- initialize variables
SET VAR vcount INTEGER = 1, vcheck1 INTEGER = 0
SET VAR vlen = (SLEN(.vzip))
WHILE vcount <= .vlen THEN
-- sum the zip code digits
SET VAR vcheck1 = +
(.vcheck1 + (INT(SGET(.vzip,1,.vcount))))
SET VAR vcount = (.vcount + 1)
ENDWH
-- calculate the check digit
SET VAR vcheck = (10 - (MOD(.vcheck1,10)))
Run a program using DECLARE CURSOR to calculate the check digit and
update existing rows of data.
*(barcode.cmd)
-- initialize variables
SET VAR vcount INTEGER = 1, vcheck1 INTEGER = 0
-- declare the cursor for the ZIP code column
-- and the primary key columns only. The primary
-- key is used to identify the row for updating.
DECLARE c1 CURSOR FOR +
SELECT empzip, empid FROM employee
OPEN c1
FETCH c1 INTO vzip i1, vempid i2
WHILE sqlcode <> 100 THEN
SET VAR vlen = (SLEN(.vzip))
WHILE vcount <= .vlen THEN
-- sum the ZIP code digits
SET VAR vcheck1 = +
(.vcheck1 + (INT(SGET(.vzip,1,.vcount))))
SET VAR vcount = (.vcount + 1)
ENDWH
-- calculate the check digit
SET VAR vcheck = (10 - (MOD(.vcheck1,10)))
-- update the row of data
UPDATE employee SET checkdigit = .vcheck +
WHERE empid=.vempid
-- reset the variables and get the next row of data
SET VAR vcount = 1, vcheck1 = 0
FETCH c1 INTO vzip i1, vempid i2
ENDWH
DROP CURS c1
RETURN
Once all rows have a check digit calculated, a report or label can be
designed and the zip code bar code font used. The report or label
needs the following expression to format the data for the font:
postal = ('s' + SGET(empzip,5,1) +
SGET(empzip,4,7) +
CTXT(checkdigit) + 's')
Locate the variable postal, select the ZipCodeBarcode font, and size
it at 16 points.
For additional information on bar codes, refer to Crystal Reports for
R:BASE on-line help.