Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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*
Posted (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 by Volte
Posted

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

Posted

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

Guest
This topic is now closed to further replies.
×
×
  • Create New...