|
-
Aug 25th, 2000, 03:18 PM
#1
Thread Starter
Lively Member
Hello. Can someone tell me what the VB procedure would be to open a text document from a location. I have tried the Shell command. Perhaps I am doing it wrong or there is another way to do it? thanks for your help!!
~Brian
-
Aug 25th, 2000, 03:21 PM
#2
Hyperactive Member
You could use:
open "c:\mydir\test.txt" for output as #1
or use the App.path object (detects where the program is being run from):
dim path as string
path = App.path + "\mydir\test.txt"
open path for output as #1
Hope this was of help!
-
Aug 25th, 2000, 03:28 PM
#3
Thread Starter
Lively Member
CyberSurfer,
I tried both of those, and they didn't work. One gave me a path error (Dimming path) and the other, just plain "open" worked, but hid the document. I want it open and in focus. Can you give me any more help?
~Brian
-
Aug 25th, 2000, 03:34 PM
#4
Hyperactive Member
I misinterpreted your problem. I thought you wanted to open a file for use in your program. One possible solution (This may not be any good - I'd need to know what you wanted to do with the open document) would be to copy all the lines of data into an array, and then put the array data into a multi-line text box.
This will only work with a *.txt file, a Random mode file, or a plain text file that has been given a different file extension.
You'll need to be a bit more specific about what you want the document open for though.
-
Aug 25th, 2000, 03:41 PM
#5
Lively Member
The 'Open For Output As' Method will work only if you want to open the text file within your program, like in a text box for example. For your problem you need ShellEx Method.
first declare this :
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
Then do this :
ShellExecute(0&, vbNullString, "C:\test.txt", vbNullString, vbNullString, vbNormalFocus)
In this case 'test.txt' will open in its default viewer.
You could also try this:
open an instance of Word and then open the file there.
I'm assuming you know the code for that. if not reply.
-
Aug 25th, 2000, 09:09 PM
#6
You can also open it this way as well.
Code:
Shell "Notepad C:\txtfile.txt", vbNormalFocus
The extension to Notepad is not needed, but you can add it if you want, it will work either way.
Code:
Shell "Notepad.exe C:\txtfile.txt", vbNormalFocus
-
Aug 28th, 2000, 08:02 AM
#7
Thread Starter
Lively Member
Great. Thanks so much for your help on this!! I will be clearer next time in posting as to what exactly i want to do.
~Brian
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
|