Using the File System Object to Read and Write ASCII Files - August 1999

I recently started using the Microsoft Scripting Runtime [SCRRUN.DLL] File System Object to read and write ASCII files. It took some time to figure out how to use it so I thought I'd pass along what I learned as the tip-of-the-month. This begins the 3rd year of these tips. Written in Denver, Colorado while on Trip USA.

The Demo Program

I wrote a VB6 demo program that reads and writes ASCII files using FSO. The demo program:

fsodemo.jpg (41793 bytes)

Using the Demo

Read - Open and read the ASCII file. Initially the demo's project file is opened and displayed. FSO will read the entire file as one Text Stream. However, I needed to examine each record so I show how to read one line at a time using method 'ReadLine'.

Write - Save the text to the ASCII file. This action overwrites the existing file, if any. FSO will write individual lines if the 'WriteLine' method is used. In this example I used the 'Write' method to write the entire text at once.

Browse - Start a common dialog to select a file. For example:

fsobrow.jpg (38962 bytes)

The Demo Uses modConnectToWebSite

The demo program uses modConnectToWebSite.bas to display this page. For details on the use of that module click here.

Download VB Code

Click here to download the VB 6 Source Code [15k].

Previous Tip   Tip Index   Next Tip 

Home

Updated 2000/10/29