Solved

CommonDialog printing

Posted on 1998-06-11
6
160 Views
Last Modified: 2010-05-03
Ok, this is a really simple problem, but I'll be damned if I can get it to work...

OK, I have a text file, called "am.txt" that I want to print from a VB program. I don't want to open it, I just want to print it to the default windows printer.

I've created a form with a Common Dialog box control, and a button. In the click event of the button is the following code:
     commondialog1.filename="c:\am.txt"
     commondialog1.action=5 '//The print dialog

Now, this displays the print dialog, but when I click on OK, nothing happens.

What have I missed?

Dan

p.s The default printer is a networked HP LaserJet 5N.
0
Comment
Question by:FaffMan
6 Comments
 
LVL 6

Expert Comment

by:anthonyc
ID: 1463086
Dan

The common dialog control does not print.....  It sets up printing

use the printer object for printing
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1463087
FaffMan,
The commonDialog only allow you to select the parameters for printing, such as printer, number of copies. It does not actually send the data to the printer. You need to write the code as to how you want your file.
One simple way is to set the PrinterDefault property to true and use the Printer object.
If you have more questions, let me know.
Regards
Dalin
0
 

Author Comment

by:FaffMan
ID: 1463088
OK, so I tried the printer.print method, but I couldn't get that to work either.

If someone can give me some code that will actually print this text file, then I'll up the points to 100.

Dan



0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 6

Accepted Solution

by:
clifABB earned 100 total points
ID: 1463089
Dim hFile As Integer
Dim sText As String

hFile = FreeFile
Open "am.txt" For Input As hFile
Do Until EOF(hFile)
  Line Input hFile, sText
  Printer.Print sText
Loop
Printer.EndDoc
0
 

Author Comment

by:FaffMan
ID: 1463090
Nice one!

I'd actually got it working already, but my code took ages to print. Your code produces results a lot faster.

Dan


0
 
LVL 6

Expert Comment

by:clifABB
ID: 1463091
Glad I could be of help.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now