Print Formatting help

Posted on 1999-01-14
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Expert Comment

ID: 1456207
Is this homework?
LVL 10

Accepted Solution

caraf_g earned 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

770 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