Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Input/Output

Status
Not open for further replies.

MikeDutcher

Technical User
Jun 19, 2001
10
US
I am learning VB 6.0. I have a file with 1 million, 600 byte records. The 600 bytes must be parsed into roughly 100 text and numeric fields. I am processing it as follows:

Open "D:\FILE.TXT" For Input As #1

Do While Not EOF(1)
cnt& = cnt& + 1
Line Input #1, in1$
ParseRec (in1$)
. . .
Loop

. . .

Sub ParseRec(in1$)
firstfield$ = Mid$(in1$, 1, 9)
. . .
lastfield& = Val(Mid$(in1$, 599, 2))
End Sub

Now I read the following in the help documentation.

"Ever since the first version of Visual Basic, files have been processed using the Open statement and other related statements and functions (listed below). These mechanisms will eventually be phased out in favor of the FSO object model, but they are fully supported in Visual Basic 6.0."

Okay, I try to be open-minded and make an attempt to understand this FSO stuff. But now I don't know how to detect the end of file. I now have

Dim fso As New FileSystemObject, fil1 As File, _
ts As TextStream

Set fil1 = fso.GetFile("D:\FILE.TXT")
Set ts = fil1.OpenAsTextStream(ForReading)

in1$ = ts.ReadLine
Do While Len(in1$) = 600
cnt& = cnt& + 1
in1$ = ts.ReadLine
ParseRec (in1$)
. . .
Loop

And eventually I get an error for attempting to read past the end of the file.

Ideas?
 
ts.AtEndOfStream

AtEndOfStream Property
See Also Example Applies To Specifics

Description

Read-only property that returns True if the file pointer is at the end of a TextStream file; False if it is not.

Syntax

object.AtEndOfStream

The object is always the name of a TextStream object.

Remarks

The AtEndOfStream property applies only to TextStream files that are open for reading; otherwise, an error occurs.

The following code illustrates the use of the AtEndOfStream property:

Dim fs, a, retstring
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.OpenTextFile("c:\testfile.txt", ForReading, False)
Do While a.AtEndOfStream <> True
retstring = a.ReadLine
...
Loop
a.Close

 
JohnYingling is correct. I'm not sure what I was thinking when I posted my reply. I blame tiredness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top