Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing A text file

Posted on 2000-04-14
9
Medium Priority
?
145 Views
Last Modified: 2010-05-02
On Command, I want to My program to print a Text file to my printer. (I have muliple printers on a network). How do I send my text file to one of these printers?
0
Comment
Question by:R_N_WARD
[X]
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
9 Comments
 

Author Comment

by:R_N_WARD
ID: 2717026
I need some help, any help, FAST!
0
 

Author Comment

by:R_N_WARD
ID: 2717078
I need some help, any help, FAST!
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2717103
Private Sub cmdPrint_Click()
Printer.Print Text1.Text
Printer.EndDoc
End Sub
0
Industry Leaders: 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!

 

Author Comment

by:R_N_WARD
ID: 2717117
AzraSound, I need to print A File like C:\Textfile.txt
0
 

Author Comment

by:R_N_WARD
ID: 2717121
AzraSound, I need to print A File like C:\Textfile.txt
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 105 total points
ID: 2717137
just load the file into a text box or a richtextbox.  richtextbox has its own load and print methods built in.

richtextbox.loadfile "filename and path"
richtextbox.SelPrint (Printer.hDC)
0
 

Author Comment

by:R_N_WARD
ID: 2717156
Thanks for the advice, AzraSound.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2717168
Adda Common Dialog control to your project (CommonDialog1) and copy and paste the following in:

<----- Code Begin ----->

   Dim strPrint As String
   Open "c:\autoexec.bat" For Binary As #1
   strPrint = Space$(LOF(1) - 1)
   Get #1, , strPrint
   Close (1)
   
   CommonDialog1.CancelError = True
   On Error GoTo PrintCancel
   CommonDialog1.ShowPrinter
   Printer.Print (strPrint)
   Printer.EndDoc
   On Error Goto 0

PrintCancel:

<----- Code End ----->
0
 
LVL 7

Expert Comment

by:BarryTice
ID: 2717192
You've got two other ways (at least).

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Sub Command1_Click()

ShellExecute me.hwnd, "Print", "File.txt", "", "C:\Path\SubPath\", &H01

End Sub


' or

Public Sub Command2_Click()

Dim intFile as Integer
Dim strText as String

intFile = FreeFile
Open "C:\Path\SubPath\File.txt" For Input As #intFile
Do While Not EOF(intFile)
    Line Input #intFile, strText
    Printer.Print strText
Loop
Close #intFile
Printer.EndDoc

End Sub
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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

688 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