=======================================================================
USER CUSTOMIZED PRINTER SETTINGS
=======================================================================
PRODUCT: R:BASE VERSION : 3.1 Or Higher
=======================================================================
AREA : PROGRAMMING CATEGORY: USER CUSTOMIZATION DOCUMENT#: 667
=======================================================================
From: Greg Lambert
11108 Chennault Beach Rd. #124
Mukilteo, WA 98275
(206) 347-5625
User customization. A difficult programming choice for even the
most experienced programmer. Often, users want the flexibility to
select peripherals and variables for their own situation. This can
provide a programming headache.
While developing an application, the need arose for the end-user to
select a different printer for report printing. This quick and
easy command file was developed to tackle just that problem.
Define the tables
-----------------
Two tables are used. The first table, PRINTERS, contains three
columns: an indexed printer number (PRINT_NUM, INTEGER), the file
name (FILE_ID, TEXT 8), and the long printer name (PRINT_NAME, TEXT
30). PRINT_NUM is an autonumbered and indexed column that just
offers a quick method of identifying printers. FILE_ID is the printer
definition (.PRD) file for each printer type. Finally, PRINT_NAME is
the long name of the printer. You can find these names in the
beginning of each printer definition file.
The second of the two tables, FACTOR, stores the printer number to
load the correct printer definition file and an id number identifying
the user. FACTOR can also be used to store other variables and
constants. This table needs at least these two columns, EMP_NUM
(INTEGER) and PRINT_NUM (INTEGER).
PRINT_NUM in the FACTOR table is linked to PRINT_NUM (the printer
number) in the PRINTERS table. The column EMP_NUM is used to
locate the correct application settings for the current user. Using
a table that stores application variables is an ideal method to
customize user settings. The column EMP_NUM could be linked to
the same column in a table called EMPLOYEE. The query searches for
the employee number as it relates to the employee who is running the
application. The employee is found by using the CVAL function to get
the name as specified in the RBASE.CFG file. Now every user can have
different printer or other settings when the application is executed.
Load the data
-------------
All the desired printer names with their corresponding printer file
names are loaded into the PRINTERS table. The first value entered in
the PRINTERS table should be R:BASE's default printer file,
NONE.PRD. Load each row of the PRINTERS table with the file id and
the printer name. The printer number is an autonumbered field and
increments as you enter each printer. For example, to load the
default printer, enter this information into the PRINTERS table:
FILE_ID PRINT_NAME
------- --------------
NONE Default
To load HP Laserjet printers you would enter:
FILE_ID PRINT_NAME
------- --------------
HPLASER1 HP LaserjetII
HPLASER1 HP LaserjetIIP
HPLASER1 HP LaserjetIII
The same printer file, HPLASER1.PRD, is used for a number of
different printers. Enter each printer name separately, but refer
all to the same printer file. This lets the user pick the printer by
the printer name; they don't need to know the file R:BASE uses. When
you enter printers, you don't need to enter the extension .PRD.
Now load the table FACTOR with the EMP_NUM for each employee. When
the user selects a printer, the FACTOR table will be updated with
that selection.
Modify the application
----------------------
Use the following commands in the application's startup file to set
up a default printer for each user based on the FACTOR table. These
commands query the FACTOR table to locate the printer number, and
query the PRINTERS table to find the corresponding printer name.
SET VAR vnum = emp_num IN employee WHERE empfname =(CVAL('name'))
SET VAR pnum = print_num IN factor WHERE emp_num = .vnum
SET VAR vfiles = file_id IN printers WHERE print_num = .pnum
SET PRINTER &vfiles
R:BASE sets the current printer to the printer specified by the
variable VFILES. If no printer has ever been selected by the user,
the printer is set to NONE (the R:BASE default). The printer files
(.PRD) need to be in the current directory or in the directory with
the R:BASE program files.
Add a menu selection to the application menu (such as Change Printer)
to run the command file, PRINTERS.CMD. When you run the command
file, it displays a scrolling menu with an alphabetical listing of
the printer names. The command used to display the menu is:
CHOOSE choice FROM #VALUES FOR DISTINCT print_name FROM PRINTERS +
ORDER BY print_name AT 7 25 RED ON GRAY CLEAR FOOTING
Scroll down to the correct printer, and press [ENTER]. PRINTERS.CMD
then sets the variable VFILES to the variable FILE_ID that holds the
newly selected printer file. The table FACTOR is updated with the
new printer number. If the [ESC] key is pressed from the menu, no
changes are made and the command file returns to where it was called
from. Additional function key trapping can be added to the code. For
example, to enchance user support, add code lines to trap the [F1]
key (help).
Whether a single or multi-user environment is in effect, customized
printer settings are quick and easy to implement with this short
command file. Now it can be easy to set up the printer for a
complicated report, or to switch printers for different reports.
*(*****************************************)
*( PRINTERS.CMD )
*( )
*( To select a printer from the list of )
*( available ones )
*(*****************************************)
SET MESSAGES OFF
SET ERROR MESSAGES OFF
SET NULL ' '
SET V choice TEXT,prtemp TEXT,vfiles TEXT,newnum INT, printer TEXT
SET V vnum = emp_num IN employee WHERE empfname =(CVAL('name'))
SET V pnum = print_num IN factor WHERE emp_num = .vnum
SET V printer = print_name IN printers WHERE print_num = .pnum
LABEL printchoice
CLS
WRITE 'ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ+
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»' AT 1 1
WRITE 'º PROGRAM NAME - +
SELECT PRINTER º' AT 2 1
WRITE 'ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ+
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ' AT 3 1
WRITE 'Current printer: ',.printer AT 5 15 YELLOW ON BLUE
WRITE 'Current printer: ',.printer AT 5 15 YELLOW ON BLUE
WRITE 'Scroll down to select your printer.' AT 6 15
CHOOSE choice FROM #VALUES FOR DISTINCT print_name FROM printers +
ORDER BY print_name AT 7 25 RED ON GRAY CLEAR FOOTING
IF choice = '[ESC]' THEN
GOTO endprog
ENDIF
SET V prtemp = print_name IN printers WHERE print_name = .choice
IF choice = .prtemp THEN
SET V vfiles = file_id, newnum = print_num +
IN printers WHERE print_name = .choice
UPDATE factor SET print_num = .newnum WHERE emp_num = .vnum
SET PRINTER &vfiles
GOTO endprog
ELSE
GOTO printchoice
ENDIF
LABEL endprog
CLEAR V choice,printer,vfiles,newnum,pnum
CLS
SET MESSAGES ON
SET ERROR MESSAGES ON
RETURN