Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 149
  • Last Modified:

Printing A text file

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
R_N_WARD
Asked:
R_N_WARD
1 Solution
 
R_N_WARDAuthor Commented:
I need some help, any help, FAST!
0
 
R_N_WARDAuthor Commented:
I need some help, any help, FAST!
0
 
AzraSoundCommented:
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!

 
R_N_WARDAuthor Commented:
AzraSound, I need to print A File like C:\Textfile.txt
0
 
R_N_WARDAuthor Commented:
AzraSound, I need to print A File like C:\Textfile.txt
0
 
AzraSoundCommented:
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
 
R_N_WARDAuthor Commented:
Thanks for the advice, AzraSound.
0
 
wsh2Commented:
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
 
BarryTiceCommented:
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

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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now