?
Solved

Using Text Files

Posted on 2003-04-01
6
Medium Priority
?
150 Views
Last Modified: 2012-05-04
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
Comment
Question by:Randy2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 8245920
set reference to scrrun.dll, probably in windows/system
0
 
LVL 14

Expert Comment

by:aelatik
ID: 8245937
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
 
LVL 4

Expert Comment

by:iozturk
ID: 8246165
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!

 

Author Comment

by:Randy2001
ID: 8246220
I am using Windows 2000.
0
 
LVL 4

Accepted Solution

by:
iozturk earned 300 total points
ID: 8246225
If win2K then reference Microsoft Scripting Runtime
0
 

Author Comment

by:Randy2001
ID: 8246307
Microsoft Scripting Runtime worked.

Thanks!
RJ
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question