|
-
Dec 19th, 2001, 04:13 AM
#1
Thread Starter
Addicted Member
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

-
Dec 19th, 2001, 07:21 AM
#2
Thread Starter
Addicted Member
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

-
Dec 19th, 2001, 07:24 AM
#3
If you Shell Notepad, it will open up a blank Notepad session into which text can be pasted, and then saved accordingly.
-
Dec 19th, 2001, 07:35 AM
#4
Thread Starter
Addicted Member
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

-
Dec 19th, 2001, 08:55 AM
#5
VB Code:
Private Sub Command1_Click()
Shell "c:\windows\notepad.exe", vbNormalFocus
End Sub
-
Dec 19th, 2001, 09:30 AM
#6
Thread Starter
Addicted Member
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

-
Dec 19th, 2001, 10:32 AM
#7
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.
-
Dec 19th, 2001, 10:39 AM
#8
Thread Starter
Addicted Member
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

-
Dec 19th, 2001, 11:09 AM
#9
-
Dec 19th, 2001, 11:24 AM
#10
Thread Starter
Addicted Member
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

-
Dec 19th, 2001, 04:17 PM
#11
Frenzied Member
OK. This code will open a file that you want with the associated program.
in a module:
VB Code:
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
Const ERROR_BAD_FORMAT = 11
Const SE_ERR_ACCESSDENIED = 5
Const SE_ERR_ASSOCINCOMPLETE = 27
Const SE_ERR_DDEBUSY = 30
Const SE_ERR_DDEFAIL = 29
Const SE_ERR_DDETIMEOUT = 28
Const SE_ERR_DLLNOTFOUND = 32
Const SE_ERR_FNF = 2
Const SE_ERR_NOASSOC = 31
Const SE_ERR_OOM = 8
Const SE_ERR_PNF = 3
Const SE_ERR_SHARE = 26
Const SW_HIDE = 0
Const SW_MAXIMIZE = 3
Const SW_MINIMIZE = 6
Const SW_RESTORE = 9
Const SW_SHOW = 5
Const SW_SHOWMAXIMIZED = 3
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMINNOACTIVE = 7
Const SW_SHOWNA = 8
Const SW_SHOWNOACTIVATE = 4
Const SW_SHOWNORMAL = 1
Sub OpenFile(sFile As String)
Dim retval As Long
retval = ShellExecute(Me.hwnd, "open", sFile, "", App.Path, _
SW_MAXIMIZE)
End Sub
usage:
OpenFile "C:\myfile.txt"
-
Dec 20th, 2001, 02:02 AM
#12
Thread Starter
Addicted Member
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

-
Dec 20th, 2001, 03:03 AM
#13
Frenzied Member
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
-
Dec 20th, 2001, 04:12 AM
#14
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|