Using "Process" component to print files

MRCP

Newcomer
Joined
Aug 25, 2003
Messages
11
I hope this is the right place to post this.
I am a beginner with VB.Net and hope someone can help me with this question. Building a program in which I want to be able to access and print pre-existing text files (created with Wordpad). From the VB.Net books I have been reading, seems like the easiest way to do this is to use the "Process" component from the Components tab of the Toolbox. Indeed, I have been able to make my program open a blank Wordpad window, but unable to make it open or recognize my pre-existing files. I have ensured that my file pathways are correct, but keep getting an error message saying my file path is not recognized. I am attempting to print files from a Collection created by my program. Via debugging I have confirmed that the For Each...Next loop I am using to process the collection is working just fine. The code is like this:

Public PMHName As String
Public PMHFormsColl As New Collection

(then intervening code to assemble the collection, which consists of variables declared as strings and assigned specific file pathways)
I then use the Components tab to add a "Process" component to the form(which I name "mdprint")

For Each PMHName in PMHFormsColl
mdprint.Start()
Next PMHName

This opens a blank Wordpad window. If I make it

mdprint.Start(PMHName)

I get the error message.
Sorry for the long post. I am totally jammed on this, any help will be much appreciated! Thanks,
MRC
 
I am responding to my own post to clarify. Just spent several more hours going through my VB books and several online VB.Net forums. It appears printing stuff with VB.Net is quite a handful as near as I can tell. It seems even to print a pre-existing text file will require great quantities of code defining just about every imaginable aspect of a document. This is quite depressing as it appears far beyond my ability to accomplish. So now just looking to confirm this as the reality of the situation so I do not waste more time trying to make it work! Are there any alternatives to "Print Document" or "Print Page"?
 
You can get Notepad to do the printing for you to the default printer using the ShellExecute API call and passing "print" in the fCommand parameter.
 
The ShellExecute API is partly what the Process class wraps - you can pass the "print" open action to a file using it.
 
Thanks for the feedback about my problem. Will ShellExecute work in VB.Net,though? I read about it on another forum and was under the impression it was a VB6 command. If it will work, can you post a sample of the syntax I should use as well? Thanks!
MRC
 
Use the Process class, as Divil says....
Visual Basic:
Dim foo As New System.Diagnostics.Process()

For Each PMHName in PMHFormsColl
   foo.StartInfo.Filename = PMHName
   foo.StartInfo.Verb = "print" '<-- Cause the file to be printed...
   foo.Start() '<-- Kick off the process...
Next
 
Back
Top