cheaney Posted December 16, 2002 Posted December 16, 2002 I am trying to open a specific file in Wordpad (from within my program) using the shell function but I don't know how to pass it the filename. This is what I have now: Dim ReturnValue On Error GoTo err_Calc ReturnValue = Shell( "C:\Program Files\WindowsNT\Accessories\wordpad.exe", 1) This code will open Wordpad but how do I get it to open my wordpad file? Thanks in advance to anyone with some help. cheaney
*Experts* Volte Posted December 16, 2002 *Experts* Posted December 16, 2002 (edited) That's a very bad way to do it for a few reasons. Number 1 is that Shell is part of the VB6 compatability library (bad). Number 2 is that Wordpad can be in a different location depending on the OS. The best way to do it is like this:Process.Start("pathtodocument")It will not necessarily start in Wordpad (possible MS Word, or something), but it will start in whatever program is assigned to the file type of your document (as if you double-clicked it in My Computer). [edit]Remember not to hardcode the path to your document. To get the path that the application is running in, use this:Application.ExecutablePath[/edit] [edit]Also, don't use On Error any more! With .NET, you can use the Try...Catch block. For example:Try Dim i As Integer i = 5 / 0 Catch ex As Exception 'there was an error; in this case, it'll be division by zero 'use the ex object that was just initialized to get information about 'the error. End Try[/edit] Edited December 16, 2002 by Volte
*Gurus* divil Posted December 16, 2002 *Gurus* Posted December 16, 2002 System.Diagnostics.Process.Start("wordpad.exe", "c:\filename.ext") That's how to pass arguments. MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
cheaney Posted December 17, 2002 Author Posted December 17, 2002 Thank you for your quick response. Your advice sounds good, however, I am using VB 6. The code you suggested....is it used in vb net? I tried it in my program with no success. I will keep trying to find the answer. If I get it I'll let you know. If not I hope you will know! :) Thanks again! cheaney
cheaney Posted December 17, 2002 Author Posted December 17, 2002 OoooHhhhh! I'm sorry! So how I got to the wrong spot! This forrum is for VB net. I'll post this question in the "pre-net" forrum. cheaney
Recommended Posts