IMPORTANT: Bar codes can easily be printed using a Report or DataWindow, designed in PowerBuilder's Report Painter or DataWindow Painter. It is very easy to modify existing Reports or DataWindows to print bar codes, or to create new ones. 

See: Printing bar codes in a Report or DataWindow

Only resort to PowerScript code if a Report or DataWindow is not sufficient.

Most people will use a Report or DataWindow to print bar codes.

Example

Using bar code functions to generating bar codes in a dialog box

To print bar codes you must use the bar code functions in the supplied PowerBuilder Library (*.PBL). Before you can use these new functions in your application you must follow these steps;

See: Adding our PowerBuilder Library to an application

See: Adding a library to the Library Search Path.

Creating an example Window

This example requires you to create a new Window.

- Run the Window Painter (Shift+F2) or click the Window icon on the toolbar;

- In the Select Window dialog box, click the New button.

Add a SingleLineEdit control

To add a SingleLineEdit control to your Window, to allow the user to enter a value;

- Select menu Control | SingleLineEdit, then click in your Window in the position you want to create the new control.

To view the properties of the new SingleLineEdit object, use any of these methods;

- Change the control's Name property to user_input.

Add a second SingleLineEdit control

Add another SingleLineEdit control to your Window, to be used to store the generated bar code.

- Change the control's Name property to user_barcode.

- Check the Display Only property.

Add a CommandButton

Now add a CommandButton control to your Window.

- Select menu Control | CommandButton, then click in your Window in the position you want to create the new control.

- Change the control's Name property to update_barcode.

- Change the control's Text property to &Update.

Add PowerScript code for the CommandButton

To add script code to the button, select the button then;

Cut and paste this very simple PowerScript code;


// ******************************************
// This is an example of code for a CommandButton event.
//
// The example code refers to two SingleLineEdit controls
// called 'user_input' and 'user_barcode'.
//
// ******************************************

// This single line of code calculates the bar code result
user_barcode.Text = CIA_CODE128 ( user_input.Text )
// Also set font and size
// but this can be done at design time
user_barcode.FaceName = "CIA Code 128 Medium"
user_barcode.TextSize = -14

This code uses function CIA_CODE128( ) to return Code 128 bar codes.

See: Bar code functions if you want to return a different type of bar code.

In any Script Window, you can quickly see a list of available bar code functions;

- Click the Paste Function button.

- Select User-defined in the Type box.

- Click OK to paste the function name in your script, or click Cancel.

 


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