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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA open file from excel cell 4 44
message box in access 4 51
VBA Shell can't Find Word document 11 112
Recommendation vb6 to or others 14 175
Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

856 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