|
-
May 18th, 2001, 10:19 AM
#1
Thread Starter
Fanatic Member
Printing a txt file
I need the simplest way possible to print an existing *.txt file
Any Help?
JO
"I have not failed. I've just found 10,000 ways that won't work."
'Thomas Edison'
"If we knew what it was we were doing it wouldn't be called research, would it?"
'Albert Einstein'
VB6
-
May 18th, 2001, 10:54 AM
#2
You can do it two ways. By opening the text file and placing the contents into a variable and printing the variable, or using the ShellExecute API function (probably takes longer) to print it.
To do it through a variable:
Code:
Private Sub Command1_Click()
Dim sText As String
Open "MyFile.txt" For Input As #1
sText = Input(LOF(1), 1)
Close #1
Printer.Print sText
Printer.EndDoc
End Sub
Or you can do it by using the ShellExecute API function:
Code:
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
Private Sub PrintFile(sFile As String)
ShellExecute Me.hwnd, "Print", sFile, _
vbNullString, vbNullString, 1 'or 0 for hidden
End Sub
Private Sub Command1_Click()
Call PrintFile("MyFile.txt")
End Sub
-
May 18th, 2001, 10:58 AM
#3
Thread Starter
Fanatic Member
Could I use this one in Form_Load event then close the form after printing?
Private Sub Command1_Click()
Dim sText As String
Open "MyFile.txt" For Input As #1
sText = Input(LOF(1), 1)
Close #1
Printer.Print sText
Printer.EndDoc
End Sub
JO
"I have not failed. I've just found 10,000 ways that won't work."
'Thomas Edison'
"If we knew what it was we were doing it wouldn't be called research, would it?"
'Albert Einstein'
VB6
-
May 18th, 2001, 11:09 AM
#4
Lively Member
'
Dim iFile As Integer
Dim cData As String
'
iFile = FreeFile
'
Open "C:\(YOURFILENAME).txt" For Input As #iFile
cData = Input(LOF(iFile), 1)
Close
'Debug.Print , cData
Printer.Print , cData
Printer.EndDoc
'
try this it whacks the whole file into a string and then prints the string, pretty quick
hope it helps
john
-
May 18th, 2001, 01:40 PM
#5
Originally posted by joltremari
Could I use this one in Form_Load event then close the form after printing?
Private Sub Command1_Click()
Dim sText As String
Open "MyFile.txt" For Input As #1
sText = Input(LOF(1), 1)
Close #1
Printer.Print sText
Printer.EndDoc
End Sub
JO
Sure.
Code:
Private Sub Form_Load()
Dim sText As String
Open "MyFile.txt" For Input As #1
sText = Input(LOF(1), 1)
Close #1
Printer.Print sText
Printer.EndDoc
DoEvents
Unload Me
Set Form1 = Nothing
End
End Sub
-
May 18th, 2001, 03:46 PM
#6
Thread Starter
Fanatic Member
"I have not failed. I've just found 10,000 ways that won't work."
'Thomas Edison'
"If we knew what it was we were doing it wouldn't be called research, would it?"
'Albert Einstein'
VB6
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
|
Click Here to Expand Forum to Full Width
|