• Welcome to Valhalla Legends Archive.
 

GoTo Error

Started by Yegg, October 21, 2004, 05:51 PM

Previous topic - Next topic

Grok

Quote from: phvckmeh on October 21, 2004, 11:48 PM
this is what i do to open txt files

Dim strPath as string
Shell "notepad " & strPath, vbNormalFocus


it always works.

Doesn't make it right.

Windows is document-centric.  You are not supposed to specify the application by which a document is to be opened for the user, but the other way around.  You ask the shell to find the appropriate server for the document type and open it.

Also, checking if the file exists prior to opening is just one way of writing good code.

Adron

Quote from: Grok on October 21, 2004, 09:29 PM
Just check if the file exists before trying to launch it?  I prefer FileSystemObject.  Go to project references, check the box beside "Microsoft Scripting Runtime".  Then ...

What about If Dir(filename) > "" Then?

LivedKrad


Grok

Quote from: Adron on October 22, 2004, 02:15 PM
Quote from: Grok on October 21, 2004, 09:29 PM
Just check if the file exists before trying to launch it?  I prefer FileSystemObject.  Go to project references, check the box beside "Microsoft Scripting Runtime".  Then ...

What about If Dir(filename) > "" Then?


That works too.  Any check is better than no check.  Does Dir(filename) handle UNC paths?  I use FileSystemObject for so much else that calling FileExists is not a costly addition.

Adron

Quote from: Grok on October 22, 2004, 10:08 PM
That works too.  Any check is better than no check.  Does Dir(filename) handle UNC paths?  I use FileSystemObject for so much else that calling FileExists is not a costly addition.

It should handle UNC paths. It just seemed confusing to call something external to do what VB could do itself.