Results 1 to 5 of 5

Thread: Open Text File In Notepad {RESOLVED}

  1. #1

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Resolved Open Text File In Notepad {RESOLVED}

    My application generates a number of .Log files. All are standard text files that I can easily view in Notepad. What I'd like to do is add a menu item which, from within my program, my user to open them and view them, in notepad. I've tried:
    VB Code:
    1. Shell "c:\myfolder\mylog.log", vbNormalFocus
    2. 'and I have tried
    3. Shell "notepad.exe c:\myfolder\mylog.log", vbNormalFocus
    And neither one works. What am I doing wrong?
    Last edited by SeanK; Feb 2nd, 2005 at 09:51 AM.
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Open Text File In Notepad

    VB Code:
    1. Shell "notepad C:\SCANDISK.LOG", vbNormalFocus

    worked fine for me Shell won't work just with the log file. It runs only exe and bat files.


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Open Text File In Notepad

    Here is exactly what I have:
    VB Code:
    1. Private Sub mnuViewLog_Click()
    2. Shell "notepad C:\AllState\LogFiles\Wednesday\ProcessLog_050202082323.log", vbNormalFocus
    3. End Sub
    And nothing happens. No errors. No log file. Are my file names and/or folder names too long?
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  4. #4
    Junior Member
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    30

    Re: Open Text File In Notepad

    Specify the full path (you might need the GetWindowsDirectory API function):

    VB Code:
    1. Shell "c:\windows\notepad.exe C:\SCANDISK.LOG", vbNormalFocus

    Note that the Shell function is not the same as Start Menu/Run program.
    Last edited by _joepsy_; Feb 2nd, 2005 at 09:46 AM.

  5. #5

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Open Text File In Notepad

    Now I remember why I HATE useing Shell. I fixed it by tossing Shell out the nearest window and using the ShellExecute API. That never fails and I don't have to worry where Notepad is on anyone's PC! If anyone is interested:
    VB Code:
    1. Option Explicit
    2.  
    3. Private 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
    4. Private Const SW_NORMAL = 1
    5.  
    6. Private Sub mnuViewLog_Click()
    7. On Error Resume Next
    8.     ShellExecute Me.hwnd, vbNullString, "C:\AllState\LogFiles\Wednesday\ProcessLog_050202082323.log",  vbNullString, "C:\", SW_SHOWNORMAL
    9. End Sub
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width