|
-
May 15th, 2000, 06:22 AM
#1
Thread Starter
Hyperactive Member
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]
-
May 15th, 2000, 01:23 PM
#2
Lively Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|