Having programmed in “C”, I became very interested in the EXTERN command in VdB. Actually, most anything is possible in VdB if you use the capability to call a function in a “C” DLL. I studied the work of the several Windows API “gurus” on the Borland Visual dBASE news group (now dbase news groups) and with the help of Charles Petzolds’ “Programming Windows” and Daniel Appleman’s “Visual Basic Programmer’s Guide to the Windows API” books, I was able to grasp the basics of using the Windows API for accessing the printer from VdB.
From there on it was just a matter of adding feature after feature. When 32 bit Visual dBASE came out and had many shortcomings in its report writer, I decided to convert the printer class to 32 bits. After a lot of work I realized it was much easier to maintain a 16/32 bit version. The current version of the printer class is 7.1 and will work the same on both versions of Visual dBASE.
How do you use the printer class?
It is really pretty simple if you don’t try to make it hard. The
class contains a sample program called skelprt.prg which is just that:
a skeleton of a printing program. Here is the basic code required
to print in either version of VdB:
* ------------- copy and paste this code --------------------------- * first you must load the printer.prg
* ------------- copy and paste this code --------------------------- |
|
That’s IT! The famous “Hello, World” printing program. I know this is only a rudimentary program, but it really only requires adding a few other methods to be able to print anything you desire. Some of the other methods that can be used are: AtSayCenter(), AtSayRight(), AtSayImage(), AtSayWrap(), AtSayWindow(). I named them “AtSay” because they act like the xBase @ 1,1 say "Hello, World" commands, i.e. AtSay(row, col, string). The printer class by default uses inches (down to the thousandth) for units of measure, but with the p.SetMapMode(cMode) this can be changed to centimeters or millimeters. It even has properties and methods that keep track of rows (p.nextRow(nRows)) that allow you to print just like prow() or whatever that function was.
For a more useful example, let’s
write a program to print mailing labels. We will use the clients.dbf table that is included in the samples directory of Visual dBASE 5.x.
Notice that I just copy the main parts of the simple example above and
then add what I need. I will assume that we are printing on Avery 5160
( 3 across x 10 down) address labels.
* ------------- copy and paste this code --------------------------- local i, k, nRowHeight
* ------------- copy and paste this code --------------------------- |
|
Perhaps in a later article I will go into more detail on printing with the printer class. For example, the class can be used to print various shapes such as ellipses (circle), squares, lines, rectangles, round cornered rectangles, pie sections, chords, and polygons. All of the closed shapes can be filled with various brushes (created with defineBrush ) and can be drawn with different pens (created with definePen). Functionality includes the ability to change orientation of the page, select paper bins, rotate fonts, change text color and background color. There is the capability to do just about anything you desire, and if it isn’t there now, it can be added without a lot of trouble.
Visual dBASE Printer Class
and other Utilities at:
http://www.dbase.com/Docs/codelib.htm
My name is Victor Alan McClung, I am married to Paula Jean and we have 4 children: John Paul 20, Laura 18, Caroline 14, and Gabriel 8. I am 56 years old ( July 12th). I work at a large aluminum smelter about 30 miles south of my home town of Sikeston, Mo. I am an electrical planner for the maintenance department. A friend got me started programming in dBASE II in CPM many years ago. I soon switched to Clipper Summer 87 and from there to 5.2. I wrote the Maintenance Information System which the plant used until we changed over to Walkers’ IMMPOWER CMMS about two years ago (the clipper program worked much better and cost millions less). I have been programming in xbase since 1986. I do a little work on the side and am in the midst of small automobile dealership program. Did you ever try print a Missouri Title Application form? Forget it without the printer class, that’s why I wrote it. Out of necessity!
I was trained in
electronics/communications in the Air Force in 1965-1968 so I have always
been interested in computers. I first taught myself to program in
assembly language on a Radio Shack TRS-80 Model 3. I then upgraded to a
Model 4 and learned “C” using Roy Soltoff’s (Misosys) “C” compiler for
the trash 80. During a strike in 1986 at the plant I dug a multi-user
CPM computer out the trash and set it up in the office and ran cables to
all the other offices in the Maintenance Planning Department. The
friend helped me get started writing the maintenance system in dBASE II.
Later they bought us 286 PC’s and I used dBASE III+. I went from there
to Summer ’87 and 5.2 as the system grew and grew. These days they
don’t want us xbase programmers writing any code and won’t buy us Visual
dBASE. Our IS manager has set a standard for the plant of MS Access
and I have told them I won’t use Access. I hate it worse than I do
Pascal.