home *** CD-ROM | disk | FTP | other *** search
- SENDING ESCAPE SEQUENCES FROM VISUAL BASIC TO HP III PRINTERS
- =============================================================
-
- Author : Peter O'Rourke (100064,475)
- Company : Tunbridge Wells Equitable Friendly Society
- Date : 9th May 1992
-
- PURPOSE
- =======
-
- This document discusses a technique for sending printer ESCape
- sequences from Visual Basic to an HPIII, something which a number of
- people have been experiencing problems with. The text might be of
- interest to users of other printers if they too are having problems.
-
- INTRODUCTION
- ============
-
- I have been working on a Visual Basic project for some time now.
- One of the functions that the system needed to perform was the sending
- of ESCape sequences to our HPIII printers. I was very disappointed to
- discover that it was not possible to do so.
-
- Despite extensive conversations with Microsoft UK & USA we were
- unable to come up with a solution. We tried using the Windows API
- function PASSTHROUGH without any success. We tried printing direct
- to LPTx also without success. Either of these solutions would probably
- work providing you sent ALL printer output via the same method. i.e
- You must NOT try to intersperse Visual Basic's internal printing
- commands. The major downside to this approach of course is that you
- lose all of VB's printer handling functions. e.g. Font selection, size,
- attributes and text alignment features.
-
- SOLUTION
- ========
-
- Robert Enigigl (76701,155) @ Microsoft suggested that I try using
- using the API function TextOut, but only if I were prepared to send ALL of
- my output via this method. I knocked together a test program, which didn't
- work either. Then I discovered, quite by accident, that if I printed
- something via Printer.Print first, and then sent my ESCapes via TextOut,
- suddenly everything worked!
-
- Now this didn't quite seem correct, since the function I had
- written to use TextOut actualy sent something via Printer.Print before it
- called the function, so that I could get the Printer Handle (HDc). After
- further investigation I discovered that it was not WHAT I was printing
- before I sent my ESCape sequences, but WHICH FONT I was using that
- determined whether or not the ESCape seqences would work.
-
- I then changed my code so that I was sending the ESCapes via the
- Printer.Print ESCString$ method, which of course is where I started some
- time ago now, and discovered that this worked fine as well.
-
- As with most things in life the final solution is so simple and
- obvious, that you want to kick yourself for not having thought of it in
- the first place. Make sure you are using the correct font BEFORE you
- send your ESCape seqences. Here is my sample code, which you can modify
- to suit:-
-
- Printer.Fontname = Printer.Fonts(ANumber)
-
- Printer.Print Chr$(27) + "&f1001y3X"
- Printer.Print Chr$(27) + "&f1004y3X"
- Printer.Print Chr$(27) + "&f1010y3X"
- Printer.Print Chr$(27) + "&f1024y3X"
- Printer.Print Chr$(27) + "&f1042y3X"
-
- Printer.Print "The rest of my data."
-
- N.B. The above ESCape codes instruct an HPIII to invoke five prestored
- macros which go to make up a composite background form for my app.
-
- By default, my setup will cause Visual Basic to use Courier as
- it's initial printer font. If I send the above ESCape sequences with
- Courier as my default font, the ESCape character (1Bh) is changed to 7Fh,
- which of course means nothing to the printer. This causes the following
- nine bytes in the ESCape sequence to be interpreted as text.
-
- The following table list the fonts that VB can access in my
- environment, and it shows whether or not the ESCape sequence is sent
- intact, or modified in some way. My environment consists of Windows 3.1
- configured to use the HPIII printer driver, which VB reports as having 16
- supported fonts.
-
- Font No. Font Name Does It Work?
- ======== ========= =================================
- 1 Courier New Yes.
- 2 Times New Roman Yes.
- 3 Wingdings Yes.
- 4 Symbol Yes.
- 5 CG Times(WN) Yes. (Tested to printer correctly)
- 6 Courier No. Escape (1Bh) becomes 7Fh.
- 7 Fences No. Escape (1Bh) becomes 95h.
- 8 Line Printer No. Escape (1Bh) becomes 7Fh.
- 9 MT Extra No. Escape (1Bh) becomes 95h.
- 10 MT Symbol No. Escape (1Bh) becomes 95h.
- 11 Symbol Yes.
- 12 Univers(WN) Yes.
- 13 MS Line Draw No. Entire ESCape sequence lost!
- 14 Roman No. Entire ESCape sequence lost!
- 15 Script No. Entire ESCape sequence lost!
- 16 Modern No. Entire ESCape sequence lost!
-
- N.B. The only font that I have actualy printed via, and therefore know
- will work, is number 5 CG Times(WN). I have only examined the disk file
- created when using the other fonts so I cannot guarantee that there won't
- be somthing else in the output that might cause problems.
-
- THANKS
- ======
-
- My thanks to the various people on Compuserve who offered advice
- along the way, but in particular Robert Einigl (76701,155) and Rick J.
- Andrews (70742,1226). Live long and prosper.
-
- Regards
- Peter O'Rourke (100064,475)
-