Results 1 to 9 of 9

Thread: OPEN "" for output as #1

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    how can I opena file,
    Code:
    Open "c:\windows\desktop\test1.txt" For Input As #1
    count the number of line
    and add a new line in the file ...

    ex.:

    before:
    Line1
    line2

    After:
    Line1
    Line2
    Line3

    cause now, my code do that :

    Line1Line2Line3

  2. #2
    Guest
    Here's how to read a text file:

    Code:
    Open "MyFile" For Input As #1 
    Text1.Text = Input$(LOF(1), 1) 
    Close #1
    And to save it:

    Code:
    Open "MyFile" For Output As #1 
    Print #1, Text1.Text 
    Close #1
    [Edited by Matthew Gates on 09-10-2000 at 02:53 AM]

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    Ok..
    there is no way to UPDATE the file..
    so..
    it,s because it will be a log fil of all a year..
    in all a scool..

  4. #4
    Guest
    Well, if you want to add to the end of it:

    Code:
    Open "MyFile" For Append As #1
    Print #1, Text1.text
    Close #1

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

    <?>

    Working with files you should use the Freefile function:
    FreeFile supplies a file number that is not already in use.

    Dim intNum as integer
    intNum = Freefile

    Open "yourpath/yourfile.ext" for Append as Intnum

    You can open tons of files this way and never have to keep track of the file numbers used. #1,#2,#3
    "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
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Code:
    Dim fn As FreeFile, i as Long
    Open FILE for Input As #fn
    Do While Not EOF(fn)
    Line Input #fn, MyStr
    i = i + 1
    Loop
    Close
    
    MsgBox "Your file contains " & i & " lines!"
    have fun!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    Did ...

    Code:
    Open "MyFile" For Append As #1
        Print #1, Text1.text
    Close #1
    ... Will add a line before put a new data :

    BEFORE1
    BEFORE2
    AFTER

    Or:

    BEFORE1
    BEFORE2AFTER







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

    <?>

    'this is the content of myfile.txt before
    Before
    Before2
    Before3

    [code]
    Option Explicit

    Private Sub Form_Load()
    Text1 = "This is after I append"

    Dim myFile As String
    Dim intNum As Integer
    myFile = "C:\my documents\myfile.txt"
    intNum = FreeFile

    Open myFile For Append As intNum
    Print #1, Text1.Text
    Close intNum

    End Sub
    [code]
    'this is it after running the above
    Before
    Before2
    Before3
    This is after I append
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    Ok..
    thak's it's exactly what I need..

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