Running the Print Mailing Labels Program

When you print with a proportionally spaced font, you must use a slightly different technique for running the program and viewing the output. If you are using a platform such as UNIX/Linux, specify the printer type with the -PRINTER:xx flag. If you are using an HP LaserJet, enter -PRINTER:HP (or -printer:hp). If you are using a PostScript printer, enter -PRINTER:PS (or -printer:ps) on the command line.

For example:

sqr ex9a username/password  -printer:hp

You can also use the -KEEP command-line flag to produce output in the SQR Portable File format and print it by using SQR Print. You still need to use the -PRINTER:xx flag when printing.

See Using the DECLARE-PRINTER Command.

The report produces the output in three columns corresponding to the dimensions of a sheet of mailing label stock. In the preceding example, the report prints the labels from left to right, filling each row of labels before moving down the page.

You can also print the labels from the top down, filling each column before moving to the next column of labels. The code to do this is shown next. The differences between this code and the previous one are shown like this. The output is not printed here, but you can run the file and view it using the same procedure that you used for the previous example.

Program ex9b.sqr
#define MAX_LABEL_LINES        10
#define LINES_BETWEEN_LABELS   3
begin-setup
  declare-layout default
    paper-size=(10,11)   left-margin=0.33
  end-declare
end-setup
begin-program
  do mailing_labels
end-program
begin-procedure mailing_labels
  let #Label_Count = 0
  let #Label_Lines = 0
  columns 1 29 57  ! enable columns
alter-printer font=5 point-size=10
begin-select
name       (0,1,30)
addr1      (+1,1,30)
city
state
zip
  move &zip to $zip xxxxx-xxxx
  let $last_line = &city || ', ' || &state || ' ' || $zipprint $last_line (+1,1,30)add 1 to #label_count
  add 1 to #label_lines
  if #label_lines = {MAX_LABEL_LINES}
    next-column goto-top=1 at-end=newpage
    let #label_lines = 0
  else
    position (+1)
    position (+{LINES_BETWEEN_LABELS})
  end-if
from customers
end-select
  use-column 0  ! disable columns
  new-page
  print 'Labels printed on ' (,1)
  print $current-date ()
  print 'Total labels printed = ' (+1,1)
  print #label_count () edit 9,999,999
end-procedure ! mailing_labels