how to print in Dos Mode and How to change Font Size ?-VBForums
Results 1 to 25 of 25

Thread: how to print in Dos Mode and How to change Font Size ?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    21

    how to print in Dos Mode and How to change Font Size ?

    I wish to dos mode printing to print bills, (Creating Text file to print). How can i change font size ?

    I saw following codes in sample for printing dos mode. Please explain usage of following codes

    Print #1, Chr(27) 'purpose ?
    Print #1, Chr(12) 'purpose ?
    Print #1, particulars; Spc(17 - Len(CStr(particulars))); ' purpose ?
    Print #1, vbCr ?

    How can i set paper size ?


    Senthil kumar.A

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,021

    Re: how to print in Dos Mode and How to change Font Size ?

    Thread moved from CodeBank forum (which is for you to post your code examples, not questions)

    Most of what you want/need (including things you haven't thought of yet) is explained by this tutorial, which is listed in the Printing section of our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)

  3. #3
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,991

    Re: how to print in Dos Mode and How to change Font Size ?

    Thats not really DOS mode as that would imply printing from a DOS console window.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    21

    Re: how to print in Dos Mode and How to change Font Size ?

    Sir, I put sample codes to know the usage these codes . Please explain me usage of these codes

  5. #5
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,991

    Re: how to print in Dos Mode and How to change Font Size ?

    did you read the links Si posted?

    The help file has documentation on the Chr function which uses the ASCII character code value. Just press F1 to bring up your help files inside of your VB.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,804

    Re: how to print in Dos Mode and How to change Font Size ?

    the sample code you posted at the top looks more like code to write a text file, i guess then that the finished text file is sent to the printer, using the dos copy (filename lpt1 or print commands
    this will only work to a parallel printer (or redirected serial printer), but not to a USB or network printer

    sending chr(27) is the escape command to tell the printer that the next character(s) are printer commands, the ctrl L (12) is the next character, can't think want ctrl L does at the moment, the third line is the string variables to be printed, in this case variable particulars and a series of spaces, vbCr is carriage return or new line

    as most of us no longer use parallel printers it is hard to test code etc for dos mode printers
    to set page sizes read your printer manual, as i don't remember specific codes to set page sizes and anyway they vary from printer to printer
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    Cyberman Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,480

    Re: how to print in Dos Mode and How to change Font Size ?

    Quote Originally Posted by westconn1
    the sample code you posted at the top looks more like code to write a text file, i guess then that the finished text file is sent to the printer, using the dos copy (filename lpt1 or print commands
    this will only work to a parallel printer (or redirected serial printer), but not to a USB or network printer

    sending chr(27) is the escape command to tell the printer that the next character(s) are printer commands, the ctrl L (12) is the next character, can't think want ctrl L does at the moment, the third line is the string variables to be printed, in this case variable particulars and a series of spaces, vbCr is carriage return or new line

    as most of us no longer use parallel printers it is hard to test code etc for dos mode printers
    to set page sizes read your printer manual, as i don't remember specific codes to set page sizes and anyway they vary from printer to printer
    under properties for that printer, you can assign it a port to use. Even network printers can be assigned a serial or parallel emulated port.
    John Lord, Evansville Indiana

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,804

    Re: how to print in Dos Mode and How to change Font Size ?

    under properties for that printer, you can assign it a port to use. Even network printers can be assigned a serial or parallel emulated port.
    ok i am interested in how to do that, can you give more detail, if i change the port for my network printer nothing will print at all
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    Cyberman Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,480

    Re: how to print in Dos Mode and How to change Font Size ?

    unfortunately i can't step you through this. I don't have a printer any more. But right click on your printer icon. It is in there somewhere.
    John Lord, Evansville Indiana

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,804

    Re: how to print in Dos Mode and How to change Font Size ?

    yeah, i know how to change the port, but that does not mean i can use the printer from dos mode
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11
    Cyberman Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,480

    Re: how to print in Dos Mode and How to change Font Size ?

    i didn't say anything about CHANGING anything. I said you can give it another one. It assigns new ports for you. Where are you getting DOS mode at? You running windows 98?

    Ok i booted up my wife's system and went through the steps.
    Step 1: right click on printer, click properties
    click the ports tab
    assign the printer one of the lpt ports (remember which one)
    from a command prompt, test it like this:
    type "test output" -> lpt1
    replace the 1 with whatever number you chose.
    John Lord, Evansville Indiana

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,804

    Re: how to print in Dos Mode and How to change Font Size ?

    i did all that before, just returned invalid port message (which makes sense, no lpt1 port), i will try again on another computer later

    thanks for trying i would like to follow this up, not quite sure why and it would not work in real dos anyway, only windows dosbox
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  13. #13
    Cyberman Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,480

    Re: how to print in Dos Mode and How to change Font Size ?

    and where exactly would you be running REAL dos? Real dos won't even read your NTFS hard drive. If you have programs that require dos, run DOSBOX (open-source). I left out something: There's also an option on there "usb port emulation" in the same list. You have to have it checked as well before you add the lpt port.
    John Lord, Evansville Indiana

  14. #14
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,002

    Re: how to print in Dos Mode and How to change Font Size ?

    You can map printers via NET USE as described in http://support.microsoft.com/kb/314499 as well.

  15. #15
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    265

    Re: how to print in Dos Mode and How to change Font Size ?

    Quote Originally Posted by imagetvr
    I wish to dos mode printing to print bills, (Creating Text file to print). How can i change font size ?

    I saw following codes in sample for printing dos mode. Please explain usage of following codes

    Print #1, Chr(27) 'purpose ?
    Print #1, Chr(12) 'purpose ?
    Print #1, particulars; Spc(17 - Len(CStr(particulars))); ' purpose ?
    Print #1, vbCr ?

    How can i set paper size ?


    Senthil kumar.A

    Chr(12) sends a Page break / New Page to the Printer

    Print #1, particulars; Spc(17 - Len(CStr(particulars)));

    Prints the contents of the variable "particulars" and prints as many spaces
    as is required to move the carraige to the 18th paosition.

    Print #1, vbCr ?

    Sends a Carriage Return to the Printer.

  16. #16
    Cyberman Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,480

    Re: how to print in Dos Mode and How to change Font Size ?

    actually those are file commands, not printer, but the rest of it's accurate.
    John Lord, Evansville Indiana

  17. #17
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    265

    Re: how to print in Dos Mode and How to change Font Size ?

    Quote Originally Posted by Lord Orwell
    actually those are file commands, not printer, but the rest of it's accurate.
    Yes you are right. My reply was a bit misleading. Sorry.

    What I meant is, when you print the file, the printer responds in such and such manner.

  18. #18
    Cyberman Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,480

    Re: how to print in Dos Mode and How to change Font Size ?

    i don't remember what it's called, but some printers use a standard set of controls for custom stuff such as font sizes, etc. This is how linux is able to use generic printer drivers for some models of printers. If you were to search linux forums for your printer, you might hit the jackpot.
    John Lord, Evansville Indiana

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    21

    Re: how to print in Dos Mode and How to change Font Size ?

    Thanks MR SVG3414

    Your reply is useful for me. Please give me idea, if possible code for

    1. Changing font and font size

    2.and alignment of numbers

    I wish to align right justified ie

    22.50
    100.00
    1522.00 like that please help me

    Thanks
    senthil kumar

  20. #20
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,021

    Re: how to print in Dos Mode and How to change Font Size ?

    Please give me idea, if possible code for
    1. Changing font and font size
    If you are printing to a .txt file, you can't - you would need to use different code, such as using the Printer (like in the tutorial I linked to), or using a different file type (which would probably be much more complex).

    2.and alignment of numbers
    You need to use either:
    • a fixed-width font (see answer to 1), and a particular amount of spaces.
    • specify the position based on the TextWidth (requires the Printer object, see the tutorial I linked to for example code for this)

  21. #21
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    265

    Re: how to print in Dos Mode and How to change Font Size ?

    Quote Originally Posted by imagetvr
    Thanks MR SVG3414

    Your reply is useful for me. Please give me idea, if possible code for

    1. Changing font and font size

    2.and alignment of numbers

    I wish to align right justified ie

    22.50
    100.00
    1522.00 like that please help me

    Thanks
    senthil kumar

    1. Regarding font size i will inform ASAP.

    2. Suppose your number is stored in a variable named num.

    print #1, format(format(num, "fixed"),"@@@@@@@@@@@@@@@")

    will right align to the 15th position with 2 decimal places.

    Hope you get the idea.

  22. #22
    Cyberman Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,480

    Re: how to print in Dos Mode and How to change Font Size ?

    this is what i was referring to. You can't have a standard text file with formatting to change the font size. You need to either print in graphics mode by printing a bitmap file, or you need to print directly to the printer and use the brand-specific control codes, or you need to use a filetype that allows you to change font sizes, such as .rtf. This is actually not that difficult since the richedit control supports this, as well as allowing you to print directly.
    John Lord, Evansville Indiana

  23. #23
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    265

    Re: how to print in Dos Mode and How to change Font Size ?

    These should work on most DMPs especially EPSON ones.
    Basically there are 3 font sizes built into the printer firmware.

    1) Normal size

    2) Large size - Use chr(14)

    Eg; Print #1, chr(14); "ABCDE"

    Will print ABCDE in large sized font. To revert back to normal size you can use chr(18)

    Eg; Print #1, chr(14); "ABCDE"; chr(18); "XYZ"

    Will print ABCDE in large sized font and XYZ in normal sized font.

    3) Condensed - Use chr(15)

    Eg; Print #1, chr(15); "ABCDE"

    Will print ABCDE in condensed font. To revert back to normal size you can use chr(18)

    Eg; Print #1, chr(15); "ABCDE"; chr(18); "XYZ"

    Will print ABCDE in condensed font and XYZ in normal sized font.

    This is all that I know.

    Regarding pagesize, there are specific codes. These may be found in the Printer manual.

    As far as I am concerned, in the progrmme I count the number of lines and send a page eject (chr(12)) when required. For example if the length of paper is 12" and you are printing @ 6 lines per inch with 1" margin on top and bottom, you can print 60 line on a sheet. After 60 lines you give a page eject to start the new page.

  24. #24

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    21

    Re: how to print in Dos Mode and How to change Font Size ?

    Hello Mr. SVG

    Thanks for your very detailed reply. Your reply very much helpful to me, I once again thanks for your reply.

    Again i have i doubt

    1. How can i give blank line between lines ? (IF i need one blank line)

    2. Suppose my paper width is 9 inches, How many characters to be printed in one line ? (horizontal line)

    Once again thankful to you

  25. #25
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    265

    Re: how to print in Dos Mode and How to change Font Size ?

    Quote Originally Posted by imagetvr
    Hello Mr. SVG

    Thanks for your very detailed reply. Your reply very much helpful to me, I once again thanks for your reply.

    Again i have i doubt

    1. How can i give blank line between lines ? (IF i need one blank line)

    2. Suppose my paper width is 9 inches, How many characters to be printed in one line ? (horizontal line)

    Once again thankful to you
    1. Print #1, vbnewline

    2. Depends on the font size. Normally it is 10 cpi. So after leaving 1 inch margin on left and right it will be 7*10 = 70 characters.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.