-
Printing Text File in VB 6
Hi,
My program maintains a log file (text file) which records the activities done. I'm trying to use the Printer Object to print the file but it's not printing properly. I tried using the PrintDocument Component too but am getting lots of errors. There is a menu bar control which when invoked should print the entire contents of the file.
I don't want the user to specify what to print. Instead, the control should directly print the entire file to the default printer. I'm & don't know what to do. Please help.
Regards,
thunder777
-
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Re: Shell Execute
Hi,
I tried to use this in a std module :
Public Const SW_SHOWNORMAL = 1
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByValhwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
& dis in my form :
Public Sub PrintThisFile(FileName As String)
Dim X As Long
X = ShellExecute(FormName, "Print", FileName, vbNullString, 0&, SW_SHOWNORMAL)
End Sub
Unfortunately, it doesn't throw up any error. It just keeps quiet & there's no printout.
Can i have some sample code to print the text file ?
Regards,
thunder777
-
What are you passing in the first parameter (FormName)? It should be a window handle (a Long integer). Try this:
X = ShellExecute(Me.hWnd, "Print", FileName, vbNullString, 0&, SW_SHOWNORMAL)
If that still doesn't work, post the value of X.
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Re: Solved
Hi,
I got it. Now it works. Thanks a lot.
Regards,
thunder777
-
May I have the entire detailed working code cuz I tried using it to print pdf docs but few of the docs are still skipped with out any error.
Also I would like to know whether the behaviour of shell32 dll is machine dependent.
Thanks for your help
-
Below is the code that I am using :
Private Sub PrintPDFs(PDFfile As String)
Dim lng As Long
lng = ShellExecuteEx(Me.hwnd, "Print", PDFfile, vbNullString, 0&, 1)
Sleep (3500)
Call TerminateProcess(lng, 0)
CloseAcrobat
End Sub
where sleep function is
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
terminate process is
Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
and shellExecute is
Public Declare Function ShellExecuteEx 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
and closeAcrobat is
Private Sub CloseAcrobat()
On Error Resume Next
'On Error GoTo ErrHandler
Dim sCmd As String '' DDE command
txtAcrobatDDE.LinkMode = 0
txtAcrobatDDE.LinkTopic = "acroview|control"
txtAcrobatDDE.LinkTimeout = 300 ' 30 sec timeout delay.
txtAcrobatDDE.LinkMode = 2
sCmd = "[AppExit()]"
txtAcrobatDDE.LinkExecute sCmd
'' Close the DDE Connection
txtAcrobatDDE.LinkMode = 0
blnAcrobatLaunched = False
Exit Sub
'ErrHandler:
'MsgBox "An error occured. Cannot Close Acrobat Reader cancelled." & " Error# " & Err.Number & vbCr & Err.Description, vbCritical, "Error: PrintPDFs"
End Sub
-
 Originally Posted by padmajage123
May I have the entire detailed working code cuz I tried using it to print pdf docs but few of the docs are still skipped with out any error.
How do you know there is no error? If you use On Error Resume Next, the error will never display. Get rid of that and see if an error does occur. Then, we can fix it.
 Originally Posted by padmajage
Also I would like to know whether the behaviour of shell32 dll is machine dependent.
That is a part of the Windows OS
Similar Threads
-
By Jenks in forum VB Classic
Replies: 6
Last Post: 05-24-2005, 02:22 PM
-
By Miles Tones in forum VB Classic
Replies: 1
Last Post: 05-20-2005, 01:57 PM
-
By Ajay M in forum VB Classic
Replies: 0
Last Post: 02-11-2002, 02:25 AM
-
By Thomas Eyde in forum .NET
Replies: 290
Last Post: 12-22-2001, 02:13 PM
-
By deborah in forum authorevents.kurata
Replies: 0
Last Post: 04-17-2000, 01:33 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|