Print Formatting help

Posted on 1999-01-14
Last Modified: 2010-05-03
I have several text files, I need to print these and include a blank line between each printed line (as in double spaced)
I am a beginner to VB so please make it as simple and detailed as possible. If it isnt too much trouble I would apreciate it if someone would write me a procedure that will do this, where I can just put in the name of the file to be printed.
Question by:TrevorCharles
  • 2
  • 2

Expert Comment

ID: 1456207
Is this homework?
LVL 10

Accepted Solution

caraf_g earned 100 total points
ID: 1456208

Dim intFile1 As Integer
Dim intFile2 As Integer
Dim strLineRead As String

intFile1 = FreeFile

Open "<your input file>" For Input As #intFile1

intFile2 = FreeFile
Open "<your output file>" For Output As #intFile2

Do While Not EOF(intFile1)
    Line Input #intFile1, strLineRead
    'Print strlineread but with double spacing
    Print #intFile2, strLineRead
    Print #intFile2, ""

Close #intFile1
Close #intFile2


Author Comment

ID: 1456209
Thanks very much for answering my question, I apreciate it. Since I posted my origional message I realized that I would need additional features in the printing part of my program.

I use a file listbox that shows the various catalog files, the user clicks any one and its contents are displayed in a textbox called Text1 and the contents of this textbox are what need to be printed double spaced.

The file content when printed will fill more than one page and I dont know how to make the printing continue until the entire contents are printed, right now I have been using


and sending it the content of the textbox, this will not print the entire files content, it stops after the first page is printed. I've been typing the file in double spaced and printing it but this seems like a kludge to me.

If it would be possible I would like to have the procedure that Caraf_g sent me modified to work with my textbox text1, I think I can then figure out on my own how to modify it for use in other ways.

One more thing, I'm putting my printing code in the mnuPrint part of my main forms menu because it seems simplest that way, if you send me code I would apreciate it if you would write it so I can continue to use it in mnuPrint, I am not experienced enough with functions yet to be able to use one and pass it the filename to be printed.

Thanks very much for you help so far.

LVL 10

Expert Comment

ID: 1456210
Instead of using a text box you could use a list box to display the contents of the file.

I assume you are using something like
Line Input #intFile1, strLineRead
to read each line from the file, so you can then use the List Box's AddItem method to add it to the list box.

Private Sub FillListBox(strFile As String)

Dim intFile1 As Integer
Dim strLineRead As String

intFile1 = FreeFile

Open strFile For Input As #intFile1

Do While Not EOF(intFile1)
    Line Input #intFile1, strLineRead
    'Print strlineread into list box with double spacing
    List1.AddItem strLineRead
    List1.AddItem ""

Close #intFile1

End Sub

'To Print, then:
For intCounter = 0 To List1.Count - 1
    Printer.Print List1.List(intCounter)

Author Comment

ID: 1456211
Once again I thank you very much for your assistance, I am very close to having what I want now.

The latest code you sent me will work quite well for the printing out of the order form, once this is printed we can use it to go around to the parts bins in the assembly room and write on it the quantity of the various parts to be ordered.

Right now a typical line of this printed form would read:

90633A009             1/4 x 20 x 1 3/4 Panhead Machine Screw

would there be a way to add a certain number of underscores after the part number as in:


If this could be done then it would be easier for the person making up the order to write the quantity needed on top of the underscores.

Earlier I forgot to mention that only when the ordering form is actually printed that it should be doublespaced, when it is just displayed in the listbox or textbox it should appear single spaced.


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA Excel: fill / replace values based on a config sheet. 5 61
Window placement 17 75
MsgBox 2 47
Passing a Text Box name to a Sub 6 75
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now