Using Shell

Status
Not open for further replies.

cheaney

New member
Joined
Sep 3, 2002
Messages
3
Location
Ontario, Canada
I am trying to open a specific file in Wordpad (from within my program) using the shell function but I dont 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
 
Thats 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:
Code:
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:
Code:
Application.ExecutablePath
[/edit]

[edit]Also, dont use On Error any more! With .NET, you can use the
Try...Catch block. For example:
Code:
Try
  Dim i As Integer
  i = 5 / 0

Catch ex As Exception
  there was an error; in this case, itll be division by zero
  use the ex object that was just initialized to get information about
  the error.
End Try
[/edit]
 
Last edited by a moderator:
Code:
System.Diagnostics.Process.Start("wordpad.exe", "c:\filename.ext")

Thats how to pass arguments.
 
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 Ill let you know. If not I hope you will know! :)

Thanks again!

cheaney
 
OoooHhhhh! Im sorry! So how I got to the wrong spot! This forrum is for VB net. Ill post this question in the "pre-net" forrum.

cheaney
 
Status
Not open for further replies.
Back
Top