• 0

[vb.net] Opening files in notepad


Question

5 answers to this question

Recommended Posts

  • 0
  Menge said:
i believe it'd be more correct to do

shell("notepad.exe filename")

since the windows dir in in the PATH environment variable and the win install dir may vary :)

585495784[/snapback]

I agree, try not to hardcode, avoid it at most times.

  • 0

another option is the ShellExecute function. This executes the associated program. (ie Notepad, IE, Netscape) Whatever is the default association with the extention you are working with.

Be aware, it will not SPECIFICALLY open NOTEPAD, but whatever application the user has associated with the file type. This can be good or bad depending on your needs.

Example

'Constant for Shell Exec

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Global Const SW_SHOWNORMAL = 1

Dim sValue As String

Dim lRet As Long

sValue = "c:\temp\information.txt"

lRet = ShellExecute(Me.hwnd, vbNullString, sValue, vbNullString, Left$(sValue, 3), SW_SHOWNORMAL)

Edited by jameswjrose
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.