LB Booster
Programming >> Liberty BASIC language >> printing to printer
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1434616439

printing to printer
Post by hammerjit on Jun 18th, 2015, 08:33am

Hi, can someone help me out here. I want to print data from a text file. Imagine my data file is like this

0, Start, 0, 0, 0
P, Jones, Joyce, 22, 5.6
P, Newman, Bill, 26, 0.35
P, Abercrombe, Tom Cruise, 35, 1254.25
P, Belton, Mindy, 28, 1245687.8
P, Doyle, Barbara, 15, 1040.05

Now, the output on paper would be

(skip the line with "Start") and only print records which begins with "P"
Jones (tab) 22 (tab) 5.60
Newman (tab) 26 (tab) 0.35
and so on

Can someone guide me please? Thanks
Re: printing to printer
Post by tsh73 on Jun 18th, 2015, 09:02am

Code:
data 0, Start, 0, 0, 0
data P, Jones, Joyce, 22, 5.6
data P, Newman, Bill, 26, 0.35
data Z, Abercrombe, "Tom Cruise", 35, 1254.25
data P, Belton, Mindy, 28, 1245687.8
data P, Doyle, Barbara, 15, 1040.05

for i = 1 to 6
    'read line
    read a1$, a2$, a3$, n1, n2
    'print line
    if a2$ = "Start" then [skip]

    if a1$ <> "P" then [skip]

        print a2$,n1,n2
        'same to printer
        lprint a2$,n1,n2
[skip]
next 

Re: printing to printer
Post by Rod on Jun 18th, 2015, 09:37am

Adding to that you can get a bit fancier with a graphicbox print. This is the printform.bas example tweaked a little.

Code:
    open "test.txt" for output as #t
    #t "0,Start, 0, 0, 0"
    #t "P,Jones,Joyce,22,5.6"
    #t "P,Newman,Bill,26,0.35"
    #t "P,Abercrombe,Tom Cruise,35,1254.25"
    #t "P,Belton,Mindy,28,1245687.8"
    #t "P,Doyle,Barbara,15,1040.05"
    close #t
    open "test.txt" for input as #t






    'printform.bas
    'This example program shows how to use a graphics window to produce
    'printable form without using PCL or graphics characters.  Different
    'fonts and colors are used.

    nomainwin
    WindowWidth = 800
    WindowHeight = DisplayHeight
    open "Printable Form" for graphics as #form
    #form "trapclose [quit]"

    #form "down"
    #form "backcolor 220 220 220"
    #form "size 2"
    #form "place 1 1 ; boxfilled 700 110"
    #form "font arial 16 bold"

    #form "place 20 34"
    #form "\Software Mail-in Order Form"
    #form "font arial 10"
    #form "\Mega2 Super Corporation\PO Box 1029391\Industrialtown, PA 11701\"

    #form "backcolor white"
    #form "place 1 110"
    #form "boxfilled 700 471"

    #form "place 1 471"
    #form "boxfilled 700 970"

    #form "color black ; place 20 490 ; font courier new"
    while eof(#t)=0
    line input #t,t$
    if left$(t$,1)="P" then
    p$=left$(trim$(word$(t$,2,","))+space$(24),24)
    p$=p$+left$(trim$(word$(t$,3,","))+space$(24),24)
    p$=p$+left$(trim$(word$(t$,4,","))+space$(4),4)
    p$=p$+using("########.##",val(word$(t$,5,",")))
    #form "\";p$
    end if
    wend

    #form "flush"
    confirm "Send to printer?"; answer
    if answer then #form "print svga"
    wait
    close #form
    close #t
    end



[quit]
    close #form
    close #t
    end

 

Re: printing to printer
Post by Richard Russell on Jun 18th, 2015, 11:05am

on Jun 18th, 2015, 09:37am, Rod wrote:
Adding to that you can get a bit fancier with a graphicbox print.

Not necessarily such a good idea with LBB. Because (unlike LB/JB) you can change attributes - bold, italics etc. - within a page I would normally recommend that text only printout be done using LPRINT - not least because then there's no need to display the output on the screen first!

Only if you want to mix text and graphics would I use the printform technique, and not necessarily even then, because in LBB you can mix both kinds of output on the same sheet (use the NODUMP qualifier with the PRINT command).

Richard.
Re: printing to printer
Post by tsh73 on Jun 18th, 2015, 11:47am

Quote:
Because (unlike LB/JB) you can change attributes - bold, italics etc. - within a page


Richard, could you give an example or point where it is described?

EDIT found it by search for "LPRINT" at "New features" at Help file
Re: printing to printer
Post by hammerjit on Jun 19th, 2015, 06:22am

thanks tsh73, got my code to work with your help.

Just a quick question, is there a command to forced printout on landscape mode without user interaction?
Re: printing to printer
Post by tsh73 on Jun 19th, 2015, 07:13am

Quote:
is there a command to forced printout on landscape mode without user interaction?

I have no idea but search at Liberty Basic forum returned this thread
Landscape Printing

Re: printing to printer
Post by Richard Russell on Jun 19th, 2015, 09:22am

on Jun 19th, 2015, 06:22am, hammerjit wrote:
is there a command to forced printout on landscape mode without user interaction?

It's a bit of a kludge, but you could use the published BBC routine and add the 'BBC BASIC escape' character to every line:

Code:
SUB landscape
!LOCAL psd%, dm%
!DIM psd% LOCAL 83
!!psd% = 84
!psd%!16 = 1024
!SYS "PageSetupDlg", psd%
!SYS "GlobalLock", psd%!8 TO dm%
!dm%!40 = 1
!dm%?44 = 2
!SYS "ResetDC", @prthdc%, dm%
!SYS "GlobalUnlock", psd%!8
!SYS "GlobalFree", psd%!8
!SYS "GlobalFree", psd%!12
!*MARGINS 10,10,10,10
END SUB 

Richard.
Re: printing to printer
Post by hammerjit on Jun 23rd, 2015, 01:57am

Thanks Richard...it works smiley
Re: printing to printer
Post by Richard Russell on Jun 23rd, 2015, 05:47am

In an ideal world there should be some way of setting, in code, all the things that the user can set using PAGESETUPDIALOG (i.e. the paper size, orientation and margins). Can anybody think of a sensible syntax for this?

Richard.

Re: printing to printer
Post by tsh73 on Jun 23rd, 2015, 07:00am

Quote:
Can anybody think of a sensible syntax for this?

Named parameters, like in VBA?
Not listed get default values.
If position accept list, like list of pages, let it be string "1-5, 7, 9".

Or just one big string with named parameters list inside
("pages = 1-5, 7, 9 ; orientation = landscape; leftMargin = 1.5 cm")

Re: printing to printer
Post by Richard Russell on Jun 23rd, 2015, 11:36am

on Jun 23rd, 2015, 07:00am, tsh73 wrote:
Or just one big string with named parameters list inside
("pages = 1-5, 7, 9 ; orientation = landscape; leftMargin = 1.5 cm")

So, for consistency with other LB printer settings, you are proposing something like:

Code:
PrinterSetup$ = "orientation = landscape; leftMargin = 1.5 cm" 

Richard.
Re: printing to printer
Post by tsh73 on Jun 23rd, 2015, 12:16pm

well, kind of.
May be - for consistency with LB GUI commands - get rid of "=", so it becames
Code:
PrinterSetup$ = "orientation landscape; leftMargin 1.5 cm"  

?

Re: printing to printer
Post by Richard Russell on Jun 23rd, 2015, 3:57pm

on Jun 23rd, 2015, 12:16pm, tsh73 wrote:
May be - for consistency with LB GUI commands

I think I'd be inclined to simplify even further:

Code:
    PrinterName$ = "DoPDF v7"
    PrinterFont$ = "Arial 12 bold"
    PrinterColor$ = "blue"
    PrinterSetup$ = "landscape 15 10 10 10" 

I should add that at present I have no plans for a new release of LBB but I'll make a mental note of the possibility of such additions should the atmosphere change.

Richard.

Re: printing to printer
Post by tsh73 on Jun 23rd, 2015, 4:18pm

Code:
    PrinterName$ = "DoPDF v7"
    PrinterFont$ = "Arial 12 bold"
    PrinterColor$ = "blue"
    PrinterSetup$ = "landscape 15 10 10 10" 
 

Doesn't it look like too many reserved words?
Re: printing to printer
Post by Richard Russell on Jun 23rd, 2015, 7:36pm

on Jun 23rd, 2015, 4:18pm, tsh73 wrote:
Doesn't it look like too many reserved words?

What problems do you see, and what is the alternative? Combining PrinterColor$ and PrinterSetup$ in a single new command seems to me illogical and inconsistent with the rest of LB, and the compatibility issues arising from having both are minimal.

Richard.
Re: printing to printer
Post by tsh73 on Jun 23rd, 2015, 8:03pm

I see single entity - printer - and several keywords associated with it
PrinterName$
PrinterFont$
PrinterColor$
PrinterSetup$

Suppose you will want to add two side printing or DPI setting or paper size - will you add still another word?

I think pack it all in single string is better, much like OPEN COM from LBB helpfile:
Code:
open "COMn: [baud=b] [parity=p] [data=d] [stop=s]
      [to=on|off] [xon=on|off] [odsr=on|off] [octs=on|off]
      [dtr=on|off|hs] [rts=on|off|hs|tg] [idsr=on|off]"
 

Re: printing to printer
Post by Richard Russell on Jun 24th, 2015, 04:10am

on Jun 23rd, 2015, 8:03pm, tsh73 wrote:
Suppose you will want to add two side printing or DPI setting or paper size - will you add still another word?

Of course not - those are setup features which would be set using PrinterSetup$.

Quote:
I think pack it all in single string is better

Mixing things which can only be changed before you print (e.g. page layout) with things that can be changed within a page (e.g. font and colour) is wrong in my opinion. But since we disagree to such a great extent it is probably better if I forget this feature altogether.

Richard.

Re: printing to printer
Post by tsh73 on Jun 24th, 2015, 06:59am

Quote:
Mixing things which can only be changed before you print (e.g. page layout) with things that can be changed within a page (e.g. font and colour) is wrong in my opinion.

Ok I admit I never thought of this from this point.
You are right.
Quote:
But since we disagree to such a great extent it is probably better if I forget this feature altogether.

No-no-no.
You are the boss. You asked for suggestions - here we are - but decision is yours.
And feature implemented in different way is much better then feature non-inplemented, IMHO.
Re: printing to printer
Post by hammerjit on Jun 24th, 2015, 09:09am

Richard....your suggestion is good, please do consider if there is future enhancement. smiley

btw...another question on this printing....if the output goes more than 2 pages, is there a way for us to put a header for each page? and also page number?
Re: printing to printer
Post by Richard Russell on Jun 24th, 2015, 10:50am

on Jun 24th, 2015, 09:09am, hammerjit wrote:
if the output goes more than 2 pages, is there a way for us to put a header for each page? and also page number?

I think I have a program which does that, but unfortunately it's on my PC at home and I don't have access to it where I am. Remind me in a couple of weeks.

Richard.

Reminder to Richard...
Post by SarmedNafi on Jul 11th, 2015, 10:35pm

>if the output goes more than 2 pages, is there a way for us to put a header for each page? and also page number?

I think I have a program which does that, but unfortunately it's on my PC at home and I don't have access to it where I am. Remind me in a couple of weeks.

Richard.

Re: printing to printer
Post by Richard Russell on Jul 12th, 2015, 10:25am

on Jun 24th, 2015, 10:50am, Richard Russell wrote:
I think I have a program which does that

Here is the program. It's intended as a proof-of-principle, in practice you would probably want to put the printing code in a SUB so it can be called from multiple places:

Code:
  PrinterName$ = "DoPDF v7"
  pv = 99999
  page = 1
  for i = 1 to 200
    oldpv = pv
    !pv = @vdu%!-8
    if pv < oldpv then
      lprint "THIS IS THE HEADER FOR PAGE "; page
      lprint
      page = page + 1
    end if
    lprint "This is line "; i; " of text sent to the printer"
  next
  dump 

Note that this can't work if you are relying on the 'word wrap' capability of LPRINT (unless you output each word individually), because if it wraps from one page to the next it's impossible to print the header part way through the output string.

Richard.
Re: printing to printer
Post by SarmedNafi on Jul 12th, 2015, 12:35pm

Thank you Richard,
It is a kind of you. Thank you very much.