Print Formatting help

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.
TrevorCharlesAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
caraf_gConnect With a Mentor Commented:

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, ""
Loop

Close #intFile1
Close #intFile2

0
 
jjbyersCommented:
Is this homework?
0
 
TrevorCharlesAuthor Commented:
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

 Printer.Print

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.

Trev
0
 
caraf_gCommented:
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 ""
Loop

Close #intFile1

End Sub

'To Print, then:
For intCounter = 0 To List1.Count - 1
    Printer.Print List1.List(intCounter)
Next
0
 
TrevorCharlesAuthor Commented:
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:

90633A009____

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.

Trev
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.