Results 1 to 8 of 8

Thread: simple open "c:\text.txt" statement

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    Hey all,
    I am trying to figure out the open command.
    could someone give me the simplest example of how to use this?
    I would like to open a .txt file and display it on my form.
    thanks
    pnj

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523
    Code:
    Open "C:\MyTextFile.txt" For Input As #1
    Text1.Text = Input(LOF(1),#1)
    Close #1
    I'm not sure about the correct syntax, but I'm quite sure it will work (NOTE: you should use FreeFile property instead of #1 thing)
    HTH
    (change: Use LOF instead of EOF)

    [Edited by QWERTY on 07-15-2000 at 12:02 PM]

  3. #3
    Guest
    Code:
    Dim strTemp As String
    Open "C:\txt.txt" For Input As #1
      Do Until EOF(1) = True
        Line Input #1, strTemp
        If Text1.Text = "" Then
          Text1.Text = strTemp
        Else
          Text1.Text = Text1.Text & vbCrLf & strTemp
        End If
      Loop
    Close #1

  4. #4
    New Member
    Join Date
    Jul 2000
    Posts
    11
    I think this is what you mean

    open "c:\text.txt" for input as #1 'Open the file
    do
    line input #1, textline 'Get one line of text
    print textline 'Print the line of txt
    'on your form
    loop until eof(1) 'Do until end of file
    close #1


    That should work. I just made it here so there might be some small bugs but I think you understand the code.

    Worf
    "64K should be enough"

  5. #5
    Guest
    hint:

    in a do-loop block, always put the decision clause after the Do word, unless you want to force it to run through the code at least once.

  6. #6
    New Member
    Join Date
    Jul 2000
    Posts
    11
    K. Thanks wossname I'll remember that.
    "64K should be enough"

  7. #7
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145
    I'm using a Rich TextBox and the command
    Text1.Loadfile "C:\textfile.txt"

    And for saving

    Text1.Savefile "C:\textfile.txt"

    Th string "C:\textfile.txt" can of course be substituted with a string variable.

    Pentax
    Wilhelm Tunemyr,
    Swede in London

    [email protected]

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
    Heinrich Heine (1797-1856)

    Pravda vítezi!
    (Truth prevails!)

  8. #8
    Guest
    Qwerty, regarding your post. It is not necessary to change LOF to EOF. LOF is the one you should use in this case.

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