Results 1 to 7 of 7

Thread: I can't figure out how to open a text document?!?

  1. #1

    Thread Starter
    Lively Member fujiyama17's Avatar
    Join Date
    Aug 2000
    Location
    Columbus, OH
    Posts
    91

    Unhappy

    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

  2. #2
    Hyperactive Member CyberSurfer's Avatar
    Join Date
    Aug 2000
    Location
    Old London Town
    Posts
    425
    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!

  3. #3

    Thread Starter
    Lively Member fujiyama17's Avatar
    Join Date
    Aug 2000
    Location
    Columbus, OH
    Posts
    91
    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

  4. #4
    Hyperactive Member CyberSurfer's Avatar
    Join Date
    Aug 2000
    Location
    Old London Town
    Posts
    425

    Lightbulb

    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.

  5. #5
    Lively Member
    Join Date
    Aug 2000
    Posts
    117
    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.

  6. #6
    Guest
    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

  7. #7

    Thread Starter
    Lively Member fujiyama17's Avatar
    Join Date
    Aug 2000
    Location
    Columbus, OH
    Posts
    91
    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
  •  



Click Here to Expand Forum to Full Width