Results 1 to 23 of 23

Thread: Sending raw text to a printer

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    16

    Sending raw text to a printer

    I'm trying to write a program which reads in a plain text file, adds a line to the top of it and then sends it to the printer. This line is a set of controls which the printer knows what to do with and it sets up the layout etc. of the paper.

    First of all, the file is being produced no problems and comes out exactly right. I have already sucessfully completed a Java version which runs and works perfectly, and they create identical files so I know that that's not the problem... so it must be somewhere in the sending.

    So, starting from scratch, how do you print in VB given that you have a filename "myFilename".

    Incidentally, the line that I have to add is as follows (escape is char27):
    escape + "E" + escape + "&l1H" + escape + "&l26a1O" + escape + "9" + escape + "&l0l6d12e36F" + escape + "(s0p10H" + escape + "&a3L"

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Sending raw text to a printer

    VB Code:
    1. Open "C:\PRN" For Output As #1
    2. Print Chr(27) & "E" & Chr(27) & "&l1H" & Chr(27) '& ....and so on...
    but you can not use a printer with usb port or network printer by using these codes...i dont know otherwise how to send these to the printer....
    just give a try
    VB Code:
    1. Printer.Print Chr(27) & "E" & Chr(27) & "&l1H" & Chr(27) '& ....and so on....
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Sending raw text to a printer

    basically to print from a file
    VB Code:
    1. FileNum = FreeFile
    2.         Open myFileName For Input As #FileNum
    3.         Do While Not EOF(FileNum)
    4.             Line Input #FileNum, OneLine
    5.             Printer.Print OneLine
    6.         Loop
    7.         Close (FileNum)
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    16

    Re: Sending raw text to a printer

    printer.print doesn't work. I'll probably shoot myself if I've just missed an import or something.

  5. #5
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Sending raw text to a printer

    Quote Originally Posted by Insaneogram
    printer.print doesn't work
    are you getting any error?
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    16

    Re: Sending raw text to a printer

    There's no printer class. I've looked through the object library. Is it a .net thing?

  7. #7
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Sending raw text to a printer

    no, that is vb 6.0 only...and you can open the printer object without any reference or components...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    16

    Re: Sending raw text to a printer

    Ok well what it's telling me is that Printer is not declared

  9. #9
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Sending raw text to a printer

    unbelivable....just open a new project and in the code window write
    VB Code:
    1. Printer.Print "Hai"
    2. Printer.EndDoc
    and see what happens when you execute it...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    16

    Re: Sending raw text to a printer

    Printer not declared...

  11. #11
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Sending raw text to a printer

    could you find it in the object browser, by pressing F2 key you can get the object browser and type printer in the search box and hit enter, see if you find any class there in the name of printer....
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  12. #12

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    16

    Re: Sending raw text to a printer

    No, not in the object browser. I'm using MS VB 2005 Express edition from a Microsoft Partner pack if that helps at all.

    The other solution is to find a native compiler for Java that can handle printers, since my Java program worked fine on the virtual machine. This is my first time using VB.

  13. #13
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Sending raw text to a printer

    sorry no idea, i never used vb 2005 express
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  14. #14

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    16

    Re: Sending raw text to a printer

    Where can I get a version that will allow printer.print?

  15. #15
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Sending raw text to a printer

    vb 2005 express is really vb dot net, so while someone here may know and be able to answer, you are really in the wrong forum and more likely to get an answer in the vb.net forum

    i have no idea how to print in dot net

    pete

  16. #16
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Sending raw text to a printer

    Using a PRINTER object with an ESCAPE sequence is a losing battle. The print driver gets in the way of ESCAPE sequences.

    You need to have that printer accessed as a file or maybe with some kind of "generic text" print driver (they are available - I've seen my customers use them).

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  17. #17
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Sending raw text to a printer

    Quote Originally Posted by szlamany
    You need to have that printer accessed as a file or maybe with some kind of "generic text" print driver (they are available - I've seen my customers use them).
    Windows has a Generic printer "manufacturer". One of those printers is a "Generic Text Only" printer. Just install a new printer, choosing Generic as the manufacturer and Generic Text Only as the model.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  18. #18
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Sending raw text to a printer

    That's exactly what I meant - thanks!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    16

    Re: Sending raw text to a printer

    Where do I get proper VB

  20. #20
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Sending raw text to a printer

    you dont need to change the version of your vb, just post your query in vb.net forum to get the answer..
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  21. #21

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    16

    Re: Sending raw text to a printer


  22. #22

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    16

    Re: Sending raw text to a printer

    This is seriously giving me the ****s now

  23. #23
    Addicted Member parminder's Avatar
    Join Date
    Apr 2003
    Location
    India
    Posts
    168

    Re: Sending raw text to a printer

    please see the following thread:

    http://www.vbforums.com/showthread.php?t=401045


    all is there.

    all the best

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width