QB64 Phoenix Edition
print file - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Utilities (https://qb64phoenix.com/forum/forumdisplay.php?fid=8)
+---- Thread: print file (/showthread.php?tid=2582)

Pages: 1 2


print file - bplus - 04-06-2024

i just tested lprint for making hardcopies of some code files. not bad

i added line numbers so you can see which lines are carry over from previous lines and which are the start of new program line

i tested the code below first for quick half page copy then I did an 842 line program [editor] i am working on and it handled multiple pages without skipping a beat in about 16 pages.

maybe you will find it handy or handy to mod for your purposes
Code: (Select All)
_Title "print file" 'b+ 2024-04-06

pfile$ = _OpenFileDialog$("Select file to print", _CWD$, "*.bas|*.txt", "text files", 0)
If pfile$ <> "" Then
    t$ = _ReadFile$(pfile$)
    ReDim f$(1 To 1)
    Split t$, Chr$(13) + Chr$(10), f$()
    For i = LBound(f$) To UBound(f$)
        LPrint i; " "; f$(i)
    Next
    Print "All done."
End If

' note: I buggered this twice now, FOR base 1 array REDIM MyArray (1 to 1) AS ... the (1 to 1) is not same as (1) which was the Blunder!!!
'notes: REDIM the array(0) to be loaded before calling Split '<<<< IMPORTANT dynamic array and empty, can use any lbound though
'This SUB will take a given N delimited string, and delimiter$ and create an array of N+1 strings using the LBOUND of the given dynamic array to load.
'notes: the loadMeArray() needs to be dynamic string array and will not change the LBOUND of the array it is given.  rev 2019-08-27
Sub Split (SplitMeString As String, delim As String, loadMeArray() As String)
    Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
    curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
    dpos = InStr(curpos, SplitMeString, delim)
    Do Until dpos = 0
        loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
        arrpos = arrpos + 1
        If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
        curpos = dpos + LD
        dpos = InStr(curpos, SplitMeString, delim)
    Loop
    loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
    ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
End Sub



RE: print file - Dimster - 04-07-2024

Handy little utility - thanks b for same.


RE: print file - SMcNeill - 04-07-2024

Do you really need something so complicated?  

Code: (Select All)
pfile$ = _OpenFileDialog$("Select file to print", _CWD$, "*.bas|*.txt", "text files", 0)
If pfile$ <> "" Then
    If _FileExists(pfile$) Then
        Open pfile$ For Input As #1
        Line Input #1, temp$
        Print temp$: LPrint temp$ 'print to screen and printer
    End If
End If

What's wrong with something as simple as the above?  Read a line, print a line?


RE: print file - bplus - 04-07-2024

Quote:Do you really need something so complicated?
no i guess not

Code: (Select All)

pfile$ = _OpenFileDialog$("Select file to print", _CWD$, "*.bas|*.txt", "text files", 0)
If pfile$ <> "" Then
If _FileExists(pfile$) Then
Open pfile$ For Input As #1
Line Input #1, temp$
Print temp$: LPrint temp$ 'print to screen and printer
End If
End If

Quote:What's wrong with something as simple as the above? Read a line, print a line?
nothing

in my defense, i have a copy of the file in an array to process further and your code doesn't Smile


RE: print file - Dimster - 04-08-2024

What I like about all the code using LPrint is the variety of the way to use it. If you go to the wiki there are no examples of what you can do with it or even best practice. One of the things which is not mentioned, but thanks to Steve, is how to use LPrint with color text.


RE: print file - bplus - 04-08-2024

Quote:but thanks to Steve, is how to use LPrint with color text.

?

but, but, but... didn't he tell me that lprint only does black ink on white paper?

let me see if i can find quote...

i know you can definitely do color printing even images with _printimage

here from your @dimster post in help board on same subject:

TAS
Quote:LPRINT just prints black text on whatever paper you have. It doesn't do images, page feeds, colors, or anything else. It's just for a quick print of black text on white paper (such as perhaps printing a text file).



RE: print file - Dimster - 04-08-2024

There's another Topic I started " Using LPrint and _Printimage together" which Steve demonstrated how to send color text.


RE: print file - bplus - 04-08-2024

(04-08-2024, 07:58 PM)Dimster Wrote: There's another Topic I started " Using LPrint and _Printimage together" which Steve demonstrated how to send color text.

yeah same place i quoted from, he used _printimage not lprint

   


RE: print file - Dimster - 04-08-2024

My apologies for the confusion, that sentence should have read - how to use _Printimage for color text and not LPrint. I have LPrint on my mind because it is the LPrint topic in the wiki where _Printimage is raised.


RE: print file - SMcNeill - 04-08-2024

Personally, I find _PrintImage to be even easier to use than LPRINT.  

The idea for _PrintImage is really simple:

1) Set up a screen to mimic the size/color of a piece of paper.  (white background, 8.5 x 11 scaled size)
2) Print whatever you want, in whatever colors, images, backgrounds you, want to that screen.
3) When the screen looks like you want it to, then just _PrintImage that screen to the printer.

That's all there is to it.  Smile