home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_refer / hp_esc / hpesc.txt
Text File  |  1992-05-28  |  5KB  |  119 lines

  1. SENDING ESCAPE SEQUENCES FROM VISUAL BASIC TO HP III PRINTERS
  2. =============================================================
  3.  
  4. Author    :    Peter O'Rourke (100064,475)
  5. Company    :    Tunbridge Wells Equitable Friendly Society
  6. Date    :    9th May 1992
  7.  
  8. PURPOSE
  9. =======
  10.  
  11.     This document discusses a technique for sending printer ESCape
  12. sequences from Visual Basic to an HPIII, something which a number of
  13. people have been experiencing problems with.  The text might be of
  14. interest to users of other printers if they too are having problems.
  15.  
  16. INTRODUCTION
  17. ============
  18.  
  19.     I have been working on a Visual Basic project for some time now.
  20. One of the functions that the system needed to perform was the sending
  21. of ESCape sequences to our HPIII printers.  I was very disappointed to 
  22. discover that it was not possible to do so.
  23.  
  24.     Despite extensive conversations with Microsoft UK & USA we were
  25. unable to come up with a solution.  We tried using the Windows API
  26. function PASSTHROUGH without any success.  We tried printing direct 
  27. to LPTx also without success.  Either of these solutions would probably
  28. work providing you sent ALL printer output via the same method.  i.e
  29. You must NOT try to intersperse Visual Basic's internal printing
  30. commands.  The major downside to this approach of course is that you
  31. lose all of VB's printer handling functions.  e.g. Font selection, size,
  32. attributes and text alignment features.
  33.  
  34. SOLUTION
  35. ========
  36.  
  37.     Robert Enigigl (76701,155) @ Microsoft suggested that I try using
  38. using the API function TextOut, but only if I were prepared to send ALL of
  39. my output via this method.  I knocked together a test program, which didn't
  40. work either.  Then I discovered, quite by accident, that if I printed
  41. something via Printer.Print first, and then sent my ESCapes via TextOut,
  42. suddenly everything worked!
  43.  
  44.     Now this didn't quite seem correct, since the function I had
  45. written to use TextOut actualy sent something via Printer.Print before it
  46. called the function, so that I could get the Printer Handle (HDc).  After
  47. further investigation I discovered that it was not WHAT I was printing
  48. before I sent my ESCape sequences, but WHICH FONT I was using that
  49. determined whether or not the ESCape seqences would work.
  50.  
  51.     I then changed my code so that I was sending the ESCapes via the
  52. Printer.Print ESCString$ method, which of course is where I started some
  53. time ago now, and discovered that this worked fine as well.
  54.  
  55.     As with most things in life the final solution is so simple and
  56. obvious, that you want to kick yourself for not having thought of it in
  57. the first place.  Make sure you are using the correct font BEFORE you
  58. send your ESCape seqences.  Here is my sample code, which you can modify
  59. to suit:-
  60.  
  61.    Printer.Fontname = Printer.Fonts(ANumber)
  62.    
  63.    Printer.Print Chr$(27) + "&f1001y3X"
  64.    Printer.Print Chr$(27) + "&f1004y3X"
  65.    Printer.Print Chr$(27) + "&f1010y3X"
  66.    Printer.Print Chr$(27) + "&f1024y3X"
  67.    Printer.Print Chr$(27) + "&f1042y3X"
  68.  
  69.    Printer.Print "The rest of my data."
  70.  
  71.    N.B.  The above ESCape codes instruct an HPIII to invoke five prestored
  72.    macros which go to make up a composite background form for my app.
  73.  
  74.     By default, my setup will cause Visual Basic to use Courier as
  75. it's initial printer font.  If I send the above ESCape sequences with
  76. Courier as my default font, the ESCape character (1Bh) is changed to 7Fh,
  77. which of course means nothing to the printer.  This causes the following
  78. nine bytes in the ESCape sequence to be interpreted as text.
  79.  
  80.     The following table list the fonts that VB can access in my
  81. environment, and it shows whether or not the ESCape sequence is sent
  82. intact, or modified in some way.  My environment consists of Windows 3.1
  83. configured to use the HPIII printer driver, which VB reports as having 16
  84. supported fonts.
  85.  
  86. Font No.    Font Name        Does It Work?
  87. ========    =========        =================================
  88.   1        Courier New        Yes.
  89.   2        Times New Roman        Yes.
  90.   3        Wingdings        Yes.
  91.   4        Symbol            Yes.
  92.   5        CG Times(WN)        Yes. (Tested to printer correctly)
  93.   6        Courier            No. Escape (1Bh) becomes 7Fh.
  94.   7        Fences                  No. Escape (1Bh) becomes 95h.
  95.   8        Line Printer        No. Escape (1Bh) becomes 7Fh.
  96.   9        MT Extra        No. Escape (1Bh) becomes 95h.
  97.   10        MT Symbol        No. Escape (1Bh) becomes 95h.
  98.   11        Symbol            Yes.
  99.   12        Univers(WN)        Yes.
  100.   13        MS Line Draw        No. Entire ESCape sequence lost!
  101.   14        Roman            No. Entire ESCape sequence lost!
  102.   15        Script            No. Entire ESCape sequence lost!
  103.   16        Modern            No. Entire ESCape sequence lost!
  104.  
  105. N.B.  The only font that I have actualy printed via, and therefore know
  106. will work, is number 5 CG Times(WN).  I have only examined the disk file
  107. created when using the other fonts so I cannot guarantee that there won't
  108. be somthing else in the output that might cause problems.
  109.  
  110. THANKS
  111. ======
  112.  
  113.     My thanks to the various people on Compuserve who offered advice
  114. along the way, but in particular Robert Einigl (76701,155) and Rick J.
  115. Andrews (70742,1226).  Live long and prosper.
  116.  
  117. Regards
  118. Peter O'Rourke (100064,475)
  119.