Results 1 to 14 of 14

Thread: Open default text editor

  1. #1

    Thread Starter
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233

    Open default text editor

    I asked this question before but I still have problems with it.

    How can you detect the default text editor on the system (Word, Textpad, notepad, whatever!), open that text editor and create a blank document?

    I want to paste text from a listbox in it.

    I don't want to open an existing document! Just open the text editor and create a new document.

    Thanks for your help!

    Christophe
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  2. #2

    Thread Starter
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    Ok, but the solution you suggest needs an existing file !!!!

    I don't have an existing file!
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    If you Shell Notepad, it will open up a blank Notepad session into which text can be pasted, and then saved accordingly.

  4. #4

    Thread Starter
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    eeeh, shell notepad??

    What do you mean by that?
    Can you give an example?
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Sub Command1_Click()
    2. Shell "c:\windows\notepad.exe", vbNormalFocus
    3. End Sub

  6. #6

    Thread Starter
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    This is not working either

    The path is not always correct !
    And it is not always notepad...it has to be detected which editor is the default...
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  7. #7
    jim mcnamara
    Guest
    We're not communicating - at all.

    You want the DEFAULT (this is what the system thinks).
    You want text files. As far as the system thinks, text files all have .txt extensions. Period. The file may be in textfile format and be called test.dat. But the system will not ever be able to associate the .dat file extension with textfiles, unless you create the assoication. Yourself. Windows will not do it automatically.

    Windows cannot open a file, then decide what program to run to work on the file. It ONLY uses file extensions, then opens what it thinks is the associated program.

    Give the association code above a DUMMY file name to return the name of the .EXE. Let's pretend you got back winword.exe (MSWord)

    Then you use the VB command

    Shell "C:\Program Files\Microsoft Office 2000\Office\WINWORD.EXE"

    This starts Word WITHOUT a file. It is starting the code that Windows thinks is associated with a text file.

    Anything else is pretty much nonsense.

  8. #8

    Thread Starter
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    This could be written a bit more friendly...
    Not all of us are so smart as you...
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  9. #9
    jim mcnamara
    Guest
    Sorry. I'm cranky.

  10. #10

    Thread Starter
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    Yeah ok,

    I'm a bit nervous because it won't work...
    So I'll create a dummy file and use that one to find the editor.

    I'll let you know if it works or not.
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  11. #11
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    OK. This code will open a file that you want with the associated program.

    in a module:

    VB Code:
    1. 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
    2.  
    3. Const ERROR_BAD_FORMAT = 11
    4. Const SE_ERR_ACCESSDENIED = 5
    5. Const SE_ERR_ASSOCINCOMPLETE = 27
    6. Const SE_ERR_DDEBUSY = 30
    7. Const SE_ERR_DDEFAIL = 29
    8. Const SE_ERR_DDETIMEOUT = 28
    9. Const SE_ERR_DLLNOTFOUND = 32
    10. Const SE_ERR_FNF = 2
    11. Const SE_ERR_NOASSOC = 31
    12. Const SE_ERR_OOM = 8
    13. Const SE_ERR_PNF = 3
    14. Const SE_ERR_SHARE = 26
    15. Const SW_HIDE = 0
    16. Const SW_MAXIMIZE = 3
    17. Const SW_MINIMIZE = 6
    18. Const SW_RESTORE = 9
    19. Const SW_SHOW = 5
    20. Const SW_SHOWMAXIMIZED = 3
    21. Const SW_SHOWMINIMIZED = 2
    22. Const SW_SHOWMINNOACTIVE = 7
    23. Const SW_SHOWNA = 8
    24. Const SW_SHOWNOACTIVATE = 4
    25. Const SW_SHOWNORMAL = 1
    26.  
    27.  
    28. Sub OpenFile(sFile As String)
    29. Dim retval As Long
    30. retval = ShellExecute(Me.hwnd, "open", sFile, "", App.Path, _
    31.         SW_MAXIMIZE)
    32. End Sub

    usage:
    OpenFile "C:\myfile.txt"

  12. #12

    Thread Starter
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    When I try this code I receive an error message:

    "Invalid use of Me keyword"

    Any idea what this means?
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  13. #13
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Originally posted by chrisvl
    When I try this code I receive an error message:

    "Invalid use of Me keyword"

    Any idea what this means?
    Replace me with the forms name.

    Like.. Form1

  14. #14
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Evan - split your code onto separate lines please,
    don't put API calls on the same line !!!

    The ShellExcecute API call does all the hard work for you.
    It's used to look in the registry for a file type, and open a
    passed in filename with it's default extension.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

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