Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

Using Text Files

I got the code below from the Mircosoft Site to work with text files.  I am getting errors that make me think I need to set a reference to use this but am unable to find one.  Any idea what reference I set??


    Dim fso As New FileSystemObject, txtfile, _
      fil1 As File, ts As TextStream
    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
0
Randy2001
Asked:
Randy2001
1 Solution
 
deightonCommented:
set reference to scrrun.dll, probably in windows/system
0
 
aelatikCommented:
Use this, its better than FSO and doesnt need a reference..

'Write a text file
Open "c:\text.txt" For Append As #1
Print #1, "Write Line 1"
Print #1, "Write Line 2"
Close #1

'read out a textfile
Open "c:\text.txt" For Input As #1
    While Not EOF(1)
    Line Input #1, NewLine
    MsgBox NewLine
    Wend
    Close #1
0
 
iozturkCommented:
If you are using NT or 95 (I am not sure with 98) you should install WSH (Windows Scripting Host) that can be found on microsoft  web site.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Randy2001Author Commented:
I am using Windows 2000.
0
 
iozturkCommented:
If win2K then reference Microsoft Scripting Runtime
0
 
Randy2001Author Commented:
Microsoft Scripting Runtime worked.

Thanks!
RJ
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now