Results 1 to 3 of 3

Thread: read & write a file

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    55

    Question

    hi
    i want to open a file and save all of it to a variable and then to write it to a new file.
    how can i do it?

  2. #2
    Guest
    Code:
    Function OpenFile(Filename As String) As String
    On Error Resume Next
    Open Filename For Input As #1
    OpenFile = Input(LOF(1), 1)
    Close #1
    End Function
    
    Private Sub SaveFile(Filename As String, Text As String)
    On Error Resume Next
    Open Filename For Output As #1
    Print #1, Text
    Close #1
    End Sub

  3. #3
    Lively Member
    Join Date
    Apr 2000
    Posts
    110

    Open the file for binary access...

    Ok, i hope i beat megatron to this... Here goes!

    The following code shows how to read the contents of a file into a string (change to variant if ya want), then place them into a new file. If you just simply want to copy the file, then use filecopy:
    Code:
    FileCopy "C:\Test.txt", "C:\NewFile.txt"
    Other wise, use the following code.
    Code:
    Dim strData as string
    
    'Get Data
    Open "C:\Test.txt" for binary as #1
    strData = Space(LOF(1))
    get #1, , strData
    Close #1
    
    'Put the data into a new file
    Open "C:\MyNewFile.txt" For binary as #1
    Put #1, strData
    Close #1
    Hope this helps...

    Laterz

    REM




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