Results 1 to 8 of 8

Thread: OPEN Files

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    143
    Hello,
    How do you open a text file for editing?
    Example.

    I open a text file that has 3 lines.

    textfile1
    Hello this is vb world.
    How are you today.
    Wow im bored.
    - end of file

    Now how would i go about inserting an extra line w. out erasing the rest.

    Thanks.

  2. #2
    Guest
    To open:

    Dim strLine$
    Open "FILE" For Input As #1
    Do While Not EOF(1)
    Line Input #1, strLine$
    Text1.text = Text1.text & strLine$
    Loop
    Close #1

    To save:

    Open "FILE" For Output As #1
    Print #1, Text1.text
    Close #1

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    143
    Im just trying to edit.

    If i open a file and use it as output and then
    use the print command filenumber and text, it will erase
    all other previous text in the file.
    I am just wanting to add to it.


  4. #4
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    use the open "FILE" for append as #1
    example:
    Code:
    Dim strLine$ 
    Open "FILE" For Append As #1 
    Do While Not EOF(1) 
         Line Input #1, strLine$ 
         Text1.text = Text1.text & strLine$ 
    Loop 
    Close #1
    I think that will work. If now, just go to Kedaman's webpage, he has a good tutorial all about file opening and editing. http://www.geocities.com/kedasu/kedamans_file.htm
    Check out the rest of his site too, it's got neat stuff on it.
    <removed by admin>

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    You need to open for Append to add to the file.
    Output will overwrite the entire file.

    Matthew knows this, it's a slip of the typo.
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        'use a multiline text box with scrollbars
        Dim i As Integer
        Dim myVar As String
        Text1 = ""
        
        Open "C:\my documents\myfile.txt" For Input As #1
         Do While Not EOF(1)
            Line Input #1, myVar
            If i = 0 Then
              Text1 = myVar & vbNewLine
            Else
              Text1 = Text1 & myVar & vbNewLine
            End If
              i = i + 1
            
         Loop
           Close
           
    End Sub
    Private Sub Command1_Click()
        'once you have made your changes in the text box
        'ie added a fourth line
        Open "C:\my documents\myfile.txt" For Append As #1
         Print #1, Text2.Text
         Close #1
         'refresh
         Call Form_Load
         Text2 = ""
         Text2.SetFocus
         
    End Sub

    [/code]

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    143
    Okay i got it finally

    Thanks guys...


  7. #7
    Guest
    You are absolutely right Wayne.
    I had Append at first. Than I changed it, than I said to myself, that's not right, than my brother came in and needed help studying for a test and I posted the reply and got distracted and all. Anyways, always go with what you gut feeling tells you. (from Who Wants to be a Millionaire?)

    We all make mistake, no ones perfect.

    Look at what Wayne does sometimes...

    [code]
    MyCode
    'and then he puts:
    [code]
    again and forgets to close your opened code tag ([/code]).

    That annoys me the hell out of me, hehe, but I learn to deal with it .

  8. #8
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    You mean this.
    [code]


    Code:
    
    
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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