Using Shell

Status
Not open for further replies.

cheaney

Newcomer
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 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
 
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:
Visual Basic:
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:
Visual Basic:
Application.ExecutablePath
[/edit]

[edit]Also, don't use On Error any more! With .NET, you can use the
Try...Catch block. For example:
Visual Basic:
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]
 
Last edited:
Visual Basic:
System.Diagnostics.Process.Start("wordpad.exe", "c:\filename.ext")

That's 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 I'll let you know. If not I hope you will know! :)

Thanks again!

cheaney
 
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
 
Status
Not open for further replies.
Back
Top