Results 1 to 2 of 2

Thread: Aaargh!! MS example giving me runtime error '70'

  1. #1

    Thread Starter
    Hyperactive Member Sal's Avatar
    Join Date
    Mar 2000
    Posts
    262

    Unhappy FileSystemObject - Aaaaargh!!! Runtime error '70'

    Microsoft Visual Basic 6.0 Programmers Guide page 740 contains an example which is giving me a runtime error. I have checked every line of code, and this error still exists. I have included the scrrun.dll and it still does it. Any ideas? Here is the code:

    Public Sub Read_Files()
    Dim fso As New fileSystemObject, txtfile, fil1 As File, ts As TextStream
    Set txtfile = fso.CreateTextFile("c:\testfile.txt", True)
    MsgBox "Writing file"
    ' Write a line.
    Set fil1 = fso.Getfile("c:\testfile.txt")
    Set ts = fil1.OpenAsTextStream(ForWriting)
    ts.write "Hello World"
    ts.Close
    'read the contents of the file
    Set ts = fil1.OpenAsTextStream(ForReading)
    s = ts.readline
    MsgBox s
    ts.Close

    End Sub

    [Edited by Sal on 05-15-2000 at 07:24 PM]

  2. #2
    Lively Member
    Join Date
    Mar 2000
    Posts
    82
    the problem is that the testfile is already opened as a textstream by the fso.createtextfile(). this returns as textstream object when it creates the file. So, first change your dim statement to read "txtfile as textstream" then after the fso.createtextfile() close that textstream (txtfile.close) or since you already have the object, just use that one and skip reopening the textstream
    Code:
    Public Sub Read_Files()
    
        Dim fso As New fileSystemObject, txtfile, fil1 As File, ts As TextStream
        Dim s As String
        Set ts = fso.CreateTextFile("c:\testfile.txt", True)
        MsgBox "Writing file"
        ' Write a line.
        ts.write "Hello World"
        ts.Close
        'read the contents of the file
        Set ts = fso.OpenTextFile("c:\testfile.txt", ForReading)
        s = ts.readline
        MsgBox s
        ts.Close
    
    End Sub
    VB 6.0 Pro | VC++ 6.0

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