DOT Matrix Printing from VB 6

vb6 India
  • 16 years ago

    Hello every body,


    I need a small help in visual basic and its very urgent..


    i got a big problem when printing on to dot matrix printer from vb 6.


    i think u people know that we can print in different fonts on matrix.


    i am printing on to the dot matrix printer but the problem is


    i want to change the fonts (compress mode, normal mode, big fonts so on)


    we got some special charecters to do this


    for example we got ascii charecter 15 to chage to compress mode...


    like that what are the other charecters and how to shift from one mode to


    other mode..


    i am in urgent need of it...


    any body help me..


    thank you.


    sudhakar

  • 16 years ago

    It seems that you have an Epson Compatible printer and you want to control the printing without windows drivers, the drivers do this stuff but if you want to send the output to lpt port directly you have to use such codes.


    Here is a good list of this codes.


    http://webpages.charter.net/dperr/links/esc_p83.htm


    You have to send such codes (not all work for all models) before the affected text, the most of them work like switches, you have to turn it off, others work for a line of text, most of them work with the  <ESC> CODE == Chr(27), and some of them are additive (you can compress and have 128 Characters or use it with Select 12 cpi Characters and have 198 characters per line).


    To cancel compressed you need to change to 10 cpi Characters

  • 16 years ago

    Thank You Darius.....


    Thank You very much.....


    It will be helpfull for me.....


    Again Thank You very much....

  • 16 years ago

    Anytime, If you need some more help no problem, I forgot to tell you that you can also send Company Logos with your report but the trick is to make a logo ready for printing, copy it to the new report file attach all info and send it to the printer not with the "Open "lpt1" for output " but with a shell Command /c Copy ??????.???


  • 16 years ago
    Hai Darius,

    if i have to use a printer driver to handle this printing work what i have to do in vb...

    i didn't got any code to do this..

    how to make the printer driver to change the fonts ....

    do you got any example for that...

    previous file(charecters) u have given is working perfectly... but from the next

    projects on wards i want the printer driver to handle that work...

    how to do it...

    i checked that with crystal reports and others... there printing is very slow on dot matrix.. its taking the graphic output....

    do we got any tools like crystal reports which will create report for us to be printed on dot matrix...

    its not urgent ... i want to know it..

    thank you,

    bye

    Ch. V. Sudhakar
  • 16 years ago

    Use ESC chains. It's simply













    VB step-by-step tutorial http://www.geocities.com/oflameron/

  • 15 years ago

    Hai All;
    kindly send me how the escape sequence send to the dot matrix printer using VB6

  • 15 years ago

    For ESC codes http://support.epson.ru/products/manuals/000352/part3.pdf


    being ESC = CHR(27)


    First, did you readed the entire post?,


    First option: you can use the VB default printer object with the specific printer or something similar.
    Second option: you can use VB printer object with a ascii printer and send the codes as part of the printing.
    Third option: "Open "lpt1" for output" or shell Environ("ComSpec") & " /c Copy ??????.???"


    wich ones is of your interest?

  • 15 years ago

    Dear Sir,
    Thanks for ur valuable suggestions and help. But it is not working in my Epson LX 300+ printer. Kindly send me some sample codes in VB 6 for handling dot matrix printer (in all possible method). Kindly treat this as an urgent message.



    Thank U
    Abdul Jabbar
    [email protected]

  • 15 years ago

    You didn't said if any printing is done, I take it for granted, so I give you some text to print.


    Code:
    Private Sub Command1_Click()
    Open "lpt1" For Output As #1
       Print #1, chr(27) & "@" 'Initialize printer
       Print #1, Chr(27) & "A" & chr(10) ' set to 10/72"
       Print #1, "This is a test first row"
       Print #1, "This is a test second row"
       Print #1, Chr(27) & "A" & chr(30) ' set to 30/72"
       Print #1, Chr(27) & "E" 'Bold
       Print #1, "This is a test first row"
       Print #1, "This is a test second row"
       Print #1, Chr(27) & "F"
    Close #1
    End Sub


    Code:
    Private Sub Command2_Click()


    Open "aaa.txt" For Output As #1
       Print #1, chr(27) & "@" 'Initialize printer
       Print #1, Chr(27) & "A" & chr(10) ' set to 10/72"
       Print #1, "This is a test first row"
       Print #1, "This is a test second row"
       Print #1, Chr(27) & "A" & chr(30) ' set to 30/72"
       Print #1, Chr(27) & "E" 'Bold
       Print #1, "This is a test first row"
       Print #1, "This is a test second row"
       Print #1, Chr(27) & "F"
    Close #1


     toprinter = MsgBox("Do you want to send the file to printer", vbQuestion + vbOKCancel, "Printing confirmation")
     If to
    printer = 1 Then
     Shell Environ("ComSpec") & " /c type c:\aaa.txt>lpt1" 'or Shell Environ("ComSpec") & " /c copy c:\aaa.txt>lpt1"
     End If
    End Sub



    In case any text can't be printed and your printer is connected directly to the board, maybe your port is not LPT1, try other like LPT2 or LPT3

  • 15 years ago

    Thank U Sir,
    Most of the functions are working now. One more Help Please. What is the ESC Sequence for Load / Eject the Paper. I am tried Chr(27) &  CHR(106) & CHR(150) for reverse (Roll Back)  the printer certain distance (150/216 Inch). But I want to be the Paper in the initial position before the printer starts printing. After printing a document the printer should eject certain distance (for tearing the paper). After tearing that printed document; we can use the non printed area (the length skiped for cutting the printed matter) while we are using continues paper (Roll / Holl Papper).  For this purpose I have to be rollback the printer to the initial position. We can use Chr(27) & "@" to load the paper (Bringing to the Printer Head Position) again . How i can retain the printer posision to begining of the page?. Please give me some sample codes in VB default printer object option to set paper size into 5" X 12" (The EPSON LX 300+ Printer is not supporting Printer.PaperSize=vbPRPSUser property). Please tell how we can use an Ascii printer insted of LX 300+ Printer.


    Thank U Again
    Abdul Jabbar

  • 15 years ago
    For tear sheet check ESC EM C  - Feeds paper to tear off position

    chr(27) & chr(25) & "C"

    check  "feed paper to tear-off position"

    http://support.epson.ru/products/manuals/000195/sidm99.pdf

    I am not sure If this works but looks like... (check the ESC EM commands, I am sure there is the clue), but remember that ESC EM = chr(27) & chr(25)

    The ascii printer is just another printer (but the driver don't add any codes by it self) so you have to send the codes for formating.

    If you enter to the icon-driver in settings printer, and check the "generic/ Text only printer" properties you will see that you can add some code - it can be helpfull if you want to set something directly, but I prefere to leave all to the software.


    "vbPRPSUser constant" as far as I know when you set height and width properties the property .papersize became automatically vbPRPSUser (or 256)

    Printer.PaperSize = 256 'still you can assign it
    Printer.Height = 12 * 1440 ' 12 inches * 1440 TWIPS per inch
    Printer.Width = 5 * 1440 ' 5 inches * 1440 TWIPS per inch

    Have a nice trip
  • 15 years ago

    Thank U sir for your valuable help. I think you are not getting my doubt clearly. I will explain again sir. That is I want the paper in the initial stage before the printing started. i.e the equal  effect of pressing the load eject button in the printer.  The paper should move to the 0 position before it starts printing (It Should be applicable for all new print jobs). The code what u are given me the last mail is not possible. Thank u very much for the kindness shown to me. Once again thanks for ur help. If it is possible kindly give ur mail ID I will send u the codes what I had tried here.


    Abdul Jabbar MM

  • 15 years ago

    Abdul, check ESC EM on this document page 164
    http://support.epson.ru/products/manuals/000350/part1.pdf


    You can use chr(27) & chr(25) & "F" (front tractor) or chr(27) & chr(25) & "B" (rear tractor)


    My mail is in the left side of the user icon (near my nickname and number of posts).

  • 15 years ago

    Thank you Darius its a very valuable document.


    Ch. V. Sudhakar

  • 15 years ago

    Nice to hear from you chvsudhakar, anytime

  • 15 years ago
    chvsudhakar,

    A long time ago I worked on a program for the State Highway Department. The main program contained a menu from where the user could select any 1 of 6 separate applications to run.  The user interface for each program was written in C code while the number crunching code was written in Fortran.  The problem was the results were written to a file by the Fortran code and was so extensive that the printout was to the old dot matrix printer with the wide paper.  The State wanted everything printed on 8 1/2" x 11" paper.  What I did was put together all the ascii control codes and sequences, escape characters, etc.  based on an HP LaserJet printer into an ascii text file.  This file also included all the codes for printing 18  characters per inch, font type and for resetting the printer back to it's original state when my print job was done. This was because other people were using the same printer for their print jobs and weren't very happy when they didn't look right.  I also put the codes in for an HP Deskjet printer.

    I then wrote a little Basic program that would read the ascii text file and set all the necessary printer settings before my print job was sent to the printer.  Once my results were printed, the printer was reset to it's original state.  The program worked great and is still being used today and I am currently printing the results to a Sharp printer which is a combination copier/printer at the company where I work.

    As others mentioned in their replies, not all dot matrix printers use the same control codes and sequences.

    If your interested I will send you the information I have including the ascii text file.

    -BobL  
  • 15 years ago

    It will help me lots if u are sending the to my email [email protected]


    Thank U Sir
    Thank U very much

  • 15 years ago

    Thank you BobL.... Please mail me that codes you have included in the ascii file to [email protected].


    Better give a link in the forum so that other people who have problem with Dot Matrix printing can use them.


    Thanks to all the team members of Developer Fusion.


    Ch. V. Sudhakar

  • 15 years ago

    Hai BobL,


    Once I got the solution from Darius I recommended the same Epson printer to all my clients.  Thats why I didn't got any problem with these codes.  


    Before my first post I enquired lots of people about this DOT Matrix printing.  But no one got the solution.  Here in Developer Fusion I got the solution.  But I don't know whether it will work on all DOT Matrix printers or not and other thing is I didn't tested it on other printers.  


    Acutally I want to develop a Report Generating Tool for DOT Matrix Printer (like Crystal Reports).  I don't know whether any product like this is available or not.  I searched a lot for this but I didn't got one.  Now I started developing that tool.  It may take some time.  Once I complete it I will post it on the forum.  


    Thank you


    Ch. V. Sudhakar

  • 15 years ago
    Just Keep It Simple and it will do (no fancy codes), Almost 25 years ago I did some research by my own and found that mostly there is laser , deskjet and epson as generic standards, and laser and deskjet are almost the same but with the color included.

    I also did programs that have a file where the codes could be changed (as ascii file with the code definition or an object with the printer definition <ie. title, number of rows, font, etc>, and maybe it's a good idea to have the facility to change the codes if needed.
  • 15 years ago
    chvsudhakar,

    I finally found the info I was looking for but it was the opposite of what you wanted. What I did was go from a dot matrix to a laser or inkjet printer.  I did send you a copy of what I did and the basic was QBasic (Quick Basic) so now you know how long ago that was.  However, maybe it will help a little.

    Darius has given you some good code and good direction if you are going to try to use the dot matrix printers.  Some of the ascii codes and sequences may be hard to find because there are different brand names of printers and they do not necessarily use the same codes.  You may want to provide the end user the option to select a certain brand of printer and therefore, you will need to provide separate codes.  I did have, at one time, a good book that covered a lot of printer codes. I'll see if I can find it and let you know.

    hth,

    - BobL
  • 15 years ago

    Hi, I'm new in this forum, the reason I entered here is that i'm looking for some code in Visual Basic 6.0, that can help me to print in three different printers three different Reports.


    I mean i have to print Receipts of my sales in a EPSON TM-U220PB printer and the receipt must cointain the information of the sale (date, hour, seller, etc) directly to this printer, second the information of the product must be printed in another printer an EPSON LX-300+, and the third printer is used to print Report using a Samsung SCX-4x16 printer.


    I'm using the Data Report of Visual Basic to perform this Reports, the Report 1 and 2 (receipts and info of the product must be printed one after the other just after click on "OK") and the third Report is only used when i perform the reports (about Personal Information).


    I must select the printer obtaining the name of the printer for example:
    MyReceiptPrinter = EPSON TM-U220PB
    MyInfoProductPrinter = EPSON LX-300+
    MyReportsPrinter = Samsung SCX-4x16


    This must be saved in a .ini file (and i don't have the code to save this file 'DTMS.ini' and read the information again when the programm is started) so that each time the Programm is executed the programm itself read this information, if one printer is erased or deleted the programm must prompt to select another printer (in fact the printers are never deleted) but if the user want to Select another printer must be prompted to select the printers.


    The programm must show no Dialog Box to select the Printer because these printers are already selected since the begining, and the Data Report is not shown before printing only the third type of Report (Personal Reports) because is printed on the Samsung SCX-4x16 and it can be printed also on another printer for example a Color printer, but in fact if the Option "Show Report Before Printing" is selected or not,  the program can shows the Dialog Box or not to select the Printer.



    The structure of the DTMS.ini file must be


    [Printers]
    MyReceiptPrinter = EPSON TM-U220PB
    MyInfoProductPrinter = EPSON LX-300+
    MyReportsPrinter = Samsung SCX-4x16


    [Positions]
    X = 0
    Y = 0


    [Colors]
    Background = LightBlue
    Labels = Black


    [MenuStyle]
    Style = Office2003


    ...
    ...
    ...
    ETC


  • 15 years ago

    chvsudhakar,


    I replied with the following a couple of days ago but I think I replied at the wrong location, so i will try again...sorry about that   .


    I finally found the info I was looking for but it was the opposite of what you wanted. What I did was go from a dot matrix to a laser or inkjet printer.  I did send you (and Jabbarmma) a copy of what I did and the basic was QBasic (Quick Basic) so now you know how long ago that was.  However, maybe it will help a little.


    Darius has given you some good code and good direction if you are going to try to use the dot matrix printers.  Some of the ascii codes and sequences may be hard to find because there are different brand names of printers and they do not necessarily use the same codes.  You may want to provide the end user the option to select a certain brand of printer and therefore, you will need to provide separate codes.  I did have, at one time, a good book that covered a lot of printer codes. I'll see if I can find it and let you know.


    hth,


    - BobL  

  • 15 years ago
    Hai BobL,

    I received your mail.  I will check it and if I have any doubts I will contact you.

    Thank you very much.

    Ch. V. Sudhakar
  • 15 years ago


    I have the same problem of Jabarmm, I need a ESC code to make the same function of pressing the load/eject button of a LX-300+ printer.

    Did somebody find the solution?

    Pleeease emailme if somebody know the solution!!!.

    ocara100(chr(64))hotmail.com

    (chr(64)) = @, only to prevent spammers.
  • 15 years ago

    i need this solution too that same function as pressing the load/eject button, if anyone got the solution, please post up. or email me. thanks

    i had try this, but it does not work.

    Open "lpt1" For Output As #1
       Print #1, Chr(27) & "@"
       Print #1, Chr(27) & Chr(25) & Chr(82)
    Close #1


  • 15 years ago

    As you can see on the previous posts it seems to be

    Print #1, Chr(27) & Chr(25) & chr(67)   or   Print #1, Chr(27) & Chr(25) & "C"

    Surprise [:O]

    But still, if you post your printer model is easer to be sure.

  • 15 years ago

    i am using LX 300+. but for some reason, i am using LX 86 driver to run LX 300+ printer. thanks

  • 15 years ago

    Sorry for the delay, I was a little bit busy

    According to the like I posted before

    For ESC codes http://support.epson.ru/products/manuals/000352/part3.pdf

    LX-300 can't use such codes. So it looks like you may have a problem, sorry not to help youSad [:(] 

    Have you tried to use select printer (chr(17) / unselect printer (chr(19) codes, I am not sure but..., the documentation is too bad.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.”