Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jul 2001
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Open text file (vb6)

    Hello all,

    I just want to know how to create a textfile at runtime and actually have it open on the screen. That's it, should be simple

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Open text file (vb6)

    What do you mean by "create" a text file? Are you writing data into a text file and then opening it in Notepad, or are you just trying to open an empty file in a text editor, or what? What was the plan if Notepad is not the default text editor? Is this intended for your own machine where you know the configuration or to run anywhere?

    In any event, it's a two step question: 1) how to create a text file (look up the Open statement in on-line help) and 2) how to have it open on screen (use the Shell command).
    Charlotte

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Open text file (vb6)

    Here is a real simple example of creating and opening new text file. It assumes that Windows "Notepad" program is available.

    Public Sub OpenTextFile(strText As String, strFileName As String)

    Dim dblShell As Double

    'strText = Text to be written to file
    'strFileName = Name of file, including path

    Open strFileName For Output As #1
    Print #1, strText
    Close #1

    dblShell = Shell("Notepad.exe " & strFileName, vbNormalFocus)

    End Sub

    Example of use ( a friendly message to your users):

    Sub OpenTextFileTest()
    OpenTextFile "Hello Stupid!", "C:My DocumentsTEXTFILE.TXT"
    End Sub

    For more details read up on Open Statement, Print # Statement, Write # Statement, etc.

    HTH

Posting Permissions

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