-
Hi,
I was wondering how you can print a text file with only a certain number of lines on each page.
The code I have is not working.
Here is my code: (VB3)
Code:
Dim IFile%, sLine$, sText$
IFile = FreeFile
iInputUserFileLines = 1
'Set Cancel to True
frmViewEntries.CMDialog1.CancelError = True
On Error GoTo PrinterErr
'Display the Box
frmViewEntries.CMDialog1.Action = 5
'Get user-selected values from box
BeginPage = frmViewEntries.CMDialog1.FromPage
EndPage = frmViewEntries.CMDialog1.ToPage
NumCopies = frmViewEntries.CMDialog1.Copies
For i = 1 To NumCopies
Open sInputUserFileName For Input As #IFile
Do While Not EOF(IFile)
Line Input #IFile, sLine
'Printer.Print
sText = sText & Trim(sLine) & Chr(13) & Chr(10)
iInputUserFileLines = iInputUserFileLines + 1
If iInputUserFileLines = 70 Then
Printer.Print sText
Printer.EndDoc
Printer.NewPage
iInputUserFileLines = 1
'sText = ""
End If
DoEvents
Loop
'DoEvents
Close #IFile
Printer.EndDoc
Next
exit sub
PrinterErr:
Exit Sub
Please help.
Thanks,
JazzBass
Edited by JazzBass on 02-25-2000 at 01:19 PM
-
Try something like this:
Code:
Private Sub Command1_Click()
Dim intFFN As Integer
Dim strLine As String
Dim strPath As String
Dim intNumberOfLines As Integer
Dim intCounter As Integer
Dim strTemp As String
strPath = "C:\Test.txt"
intFFN = FreeFile
strTemp = InputBox("Enter the number of lines you want to be print on the page.")
'If the user didn't not eneter correct information, then default to 20 lines
intNumberOfLines = IIf(IsNumeric(strTemp), Val(strTemp), 20)
'Initialize the counter
intCounter = 1
Open strPath For Input As intFFN
Do Until EOF(intFFN)
Line Input #intFFN, strLine
If intCounter > intNumberOfLines Then
Printer.NewPage
'Reset the counter
intCounter = 1
End If
strLine = Trim(strLine) & vbCrLf
Printer.Print strLine
intCounter = intCounter + 1
DoEvents
Loop
Printer.EndDoc
End Sub
Assuming that you have file called C:\Test.txt
-
are you working on base 64?
-
-
Thanks Serge
Serge,
Thanks a million. That works great. :D
By the way, I have two questions. I noticed you did not put a close #intFFN line after the file was read completly. Could you explain your reason why.
Also, I'm fighting with the Common Dialog for Printing (VB3). How do I get the printer name a user selects and then send the document to that printer.
Thanks again Serge,
JazzBass
-
For your first question:
I just forgot to close the file (I was writing dirrectly into the post). Good catch JazzBass.
For your second question:
Actually, CommondDialog control has a BUG. When you select a printer from the CommonDialog control, windows change that printer to be you default. So after they select the printer, you can use Printer object (without changing anything) to print whatever you need.
Edited by Serge on 02-28-2000 at 01:56 PM
-
Thanks again Serge
Hey Serge,
Thanks for your response and the compliment. :D I'm not trying to be a pain, but that BUG you were talking about for the Common Dialog, did MS fix that in the later versions of VB? I'm just curious because if they did not, that would really stink. I haven't had a chance to try it at home on VB6. I guess I'll just have to have the users print to the default printer. Any idea as to how I can find the default printer and show the user what it is from my program?
I asked this question once before, but I got only one response and that was not for VB3.
Thanks again,
JazzBass